Ticket #14543: 14543.patch
File 14543.patch, 3.8 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/ct_framework/__init__.py
-
django/contrib/contenttypes/tests.py
2 2 from django.conf import settings 3 3 from django.contrib.contenttypes.models import ContentType 4 4 from django.contrib.sites.models import Site 5 from django.contrib.contenttypes.views import shortcut6 from django.core.exceptions import ObjectDoesNotExist7 from django.http import HttpRequest8 5 from django.test import TestCase 9 6 10 7 … … 45 42 ContentType.objects.get_for_model(ContentType) 46 43 len(db.connection.queries) 47 44 self.assertEqual(2, len(db.connection.queries)) 48 49 def test_shortcut_view(self):50 """51 Check that the shortcut view (used for the admin "view on site"52 functionality) returns a complete URL regardless of whether the sites53 framework is installed54 """55 56 request = HttpRequest()57 request.META = {58 "SERVER_NAME": "Example.com",59 "SERVER_PORT": "80",60 }61 from django.contrib.auth.models import User62 user_ct = ContentType.objects.get_for_model(User)63 obj = User.objects.create(username="john")64 Site._meta.installed = True65 response = shortcut(request, user_ct.id, obj.id)66 self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])67 Site._meta.installed = False68 response = shortcut(request, user_ct.id, obj.id)69 self.assertEqual("http://Example.com/users/john/", response._headers.get("location")[1]) -
tests/regressiontests/ct_framework/tests.py
1 from django.test import TestCase 2 from django.contrib.contenttypes.views import shortcut 3 from django.http import HttpRequest 4 from django.contrib.contenttypes.models import ContentType 5 from django.contrib.sites.models import Site 6 from models import Article 7 8 class ContentTypesTests(TestCase): 9 def test_shortcut_view(self): 10 """ 11 Check that the shortcut view (used for the admin "view on site" 12 functionality) returns a complete URL regardless of whether the sites 13 framework is installed 14 """ 15 16 request = HttpRequest() 17 request.META = { 18 "SERVER_NAME": "Example.com", 19 "SERVER_PORT": "80", 20 } 21 article_ct = ContentType.objects.get_for_model(Article) 22 obj = Article.objects.create(slug="test") 23 Site._meta.installed = True 24 response = shortcut(request, article_ct.id, obj.id) 25 self.assertEqual("http://example.com/articles/test/", response._headers.get("location")[1]) 26 Site._meta.installed = False 27 response = shortcut(request, article_ct.id, obj.id) 28 self.assertEqual("http://Example.com/articles/test/", response._headers.get("location")[1]) -
tests/regressiontests/ct_framework/models.py
1 import urllib 2 from django.db import models 3 from django.utils.encoding import smart_str 4 5 class Article(models.Model): 6 slug = models.SlugField(max_length=64) 7 8 def get_absolute_url(self): 9 return "/articles/%s/" % urllib.quote(smart_str(self.slug))