summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/contenttypes_tests/tests.py')
-rw-r--r--tests/contenttypes_tests/tests.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index c2377bf82e..a494df0340 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -12,11 +12,14 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core import checks
from django.db import connections, models
-from django.test import SimpleTestCase, TestCase, override_settings
+from django.test import SimpleTestCase, TestCase, mock, override_settings
from django.test.utils import captured_stdout, isolate_apps
from django.utils.encoding import force_str, force_text
-from .models import Article, Author, SchemeIncludedURL
+from .models import (
+ Article, Author, ModelWithNullFKToSite, SchemeIncludedURL,
+ Site as MockSite,
+)
@override_settings(ROOT_URLCONF='contenttypes_tests.urls')
@@ -94,6 +97,21 @@ class ContentTypesViewsTests(TestCase):
response = self.client.get(short_url)
self.assertEqual(response.status_code, 404)
+ @mock.patch('django.apps.apps.get_model')
+ def test_shortcut_view_with_null_site_fk(self, get_model):
+ """
+ The shortcut view works if a model's ForeignKey to site is None.
+ """
+ get_model.side_effect = lambda *args, **kwargs: MockSite if args[0] == 'sites.Site' else ModelWithNullFKToSite
+
+ obj = ModelWithNullFKToSite.objects.create(title='title')
+ url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(ModelWithNullFKToSite).id, obj.pk)
+ response = self.client.get(url)
+ self.assertRedirects(
+ response, '%s' % obj.get_absolute_url(),
+ fetch_redirect_response=False,
+ )
+
def test_create_contenttype_on_the_spot(self):
"""
Make sure ContentTypeManager.get_for_model creates the corresponding