diff options
author | Paulo <commonzenpython@gmail.com> | 2017-09-20 11:26:03 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-06-21 12:31:04 -0400 |
commit | d14850e525ccf95d42b8e9f11571dc5d18b15f03 (patch) | |
tree | cefbfc5c96557df92d72029f0ec91d0a379fee8d /tests/contenttypes_tests | |
parent | efbcd60a22dd1adc46a15528a16a1fa998b3073e (diff) | |
download | django-d14850e525ccf95d42b8e9f11571dc5d18b15f03.tar.gz |
Fixed #18620 -- Made ContentTypes shortcut view prefer current site if available.
Thanks Mike Tigas (mtigas) for the initial patch.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r-- | tests/contenttypes_tests/test_views.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/contenttypes_tests/test_views.py b/tests/contenttypes_tests/test_views.py index 72e87550d0..a26f654a02 100644 --- a/tests/contenttypes_tests/test_views.py +++ b/tests/contenttypes_tests/test_views.py @@ -106,13 +106,15 @@ class ContentTypesViewsTests(TestCase): 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) + expected_url = 'http://testserver%s' % obj.get_absolute_url() + self.assertRedirects(response, expected_url, fetch_redirect_response=False) @mock.patch('django.apps.apps.get_model') def test_shortcut_view_with_site_m2m(self, get_model): """ - When the object has a ManyToManyField to Site, redirect to the - domain of the first site found in the m2m relationship. + When the object has a ManyToManyField to Site, redirect to the current + site if it's attached to the object or to the domain of the first site + found in the m2m relationship. """ get_model.side_effect = lambda *args, **kwargs: MockSite if args[0] == 'sites.Site' else ModelWithM2MToSite @@ -138,6 +140,23 @@ class ContentTypesViewsTests(TestCase): response = self.client.get('/shortcut/%s/%s/' % (ct.pk, site_3_obj.pk)) self.assertRedirects(response, expected_url, fetch_redirect_response=False) + obj_with_sites = ModelWithM2MToSite.objects.create(title='Linked to Current Site') + obj_with_sites.sites.set(MockSite.objects.all()) + shortcut_url = '/shortcut/%s/%s/' % (ct.pk, obj_with_sites.pk) + expected_url = 'http://example2.com%s' % obj_with_sites.get_absolute_url() + + with self.settings(SITE_ID=2): + # Redirects to the domain of the Site matching the current site's + # domain. + response = self.client.get(shortcut_url) + self.assertRedirects(response, expected_url, fetch_redirect_response=False) + + with self.settings(SITE_ID=None, ALLOWED_HOSTS=['example2.com']): + # Redirects to the domain of the Site matching the request's host + # header. + response = self.client.get(shortcut_url, SERVER_NAME='example2.com') + self.assertRedirects(response, expected_url, fetch_redirect_response=False) + class ShortcutViewTests(TestCase): |