Ticket #14543: 14543.patch

File 14543.patch, 3.8 KB (added by Sayane, 13 years ago)

New patch, removed Auth app depency

  • tests/regressiontests/ct_framework/__init__.py

  • django/contrib/contenttypes/tests.py

     
    22from django.conf import settings
    33from django.contrib.contenttypes.models import ContentType
    44from django.contrib.sites.models import Site
    5 from django.contrib.contenttypes.views import shortcut
    6 from django.core.exceptions import ObjectDoesNotExist
    7 from django.http import HttpRequest
    85from django.test import TestCase
    96
    107
     
    4542        ContentType.objects.get_for_model(ContentType)
    4643        len(db.connection.queries)
    4744        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 sites
    53         framework is installed
    54         """
    55 
    56         request = HttpRequest()
    57         request.META = {
    58             "SERVER_NAME": "Example.com",
    59             "SERVER_PORT": "80",
    60         }
    61         from django.contrib.auth.models import User
    62         user_ct = ContentType.objects.get_for_model(User)
    63         obj = User.objects.create(username="john")
    64         Site._meta.installed = True
    65         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 = False
    68         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

     
     1from django.test import TestCase
     2from django.contrib.contenttypes.views import shortcut
     3from django.http import HttpRequest
     4from django.contrib.contenttypes.models import ContentType
     5from django.contrib.sites.models import Site
     6from models import Article
     7
     8class 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

     
     1import urllib
     2from django.db import models
     3from django.utils.encoding import smart_str
     4
     5class 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))
Back to Top