summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorBruno Alla <bruno.alla@founders4schools.org.uk>2017-03-07 21:00:43 +0000
committerTim Graham <timograham@gmail.com>2017-05-24 08:36:34 -0400
commit6092ea8fa62191bf9ed8ebaae3125dcde9c4bbec (patch)
tree4da8346887b1c33e3b0a993eaf780687cdb239b0 /tests/contenttypes_tests
parent91b2bc3e70be2632baad86488fb03cf02848b5b6 (diff)
downloaddjango-6092ea8fa62191bf9ed8ebaae3125dcde9c4bbec.tar.gz
Refs #27804 -- Used subTest() in several tests.
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/test_views.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/tests/contenttypes_tests/test_views.py b/tests/contenttypes_tests/test_views.py
index d1165c6818..cdfa1e0961 100644
--- a/tests/contenttypes_tests/test_views.py
+++ b/tests/contenttypes_tests/test_views.py
@@ -45,9 +45,10 @@ class ContentTypesViewsTests(TestCase):
def test_shortcut_with_absolute_url(self):
"Can view a shortcut for an Author object that has a get_absolute_url method"
for obj in Author.objects.all():
- short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk)
- response = self.client.get(short_url)
- self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(), target_status_code=404)
+ with self.subTest(obj=obj):
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk)
+ response = self.client.get(short_url)
+ self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(), target_status_code=404)
def test_shortcut_with_absolute_url_including_scheme(self):
"""
@@ -55,9 +56,10 @@ class ContentTypesViewsTests(TestCase):
the tested URLs are: "http://...", "https://..." and "//..."
"""
for obj in SchemeIncludedURL.objects.all():
- short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(SchemeIncludedURL).id, obj.pk)
- response = self.client.get(short_url)
- self.assertRedirects(response, obj.get_absolute_url(), fetch_redirect_response=False)
+ with self.subTest(obj=obj):
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(SchemeIncludedURL).id, obj.pk)
+ response = self.client.get(short_url)
+ self.assertRedirects(response, obj.get_absolute_url(), fetch_redirect_response=False)
def test_shortcut_no_absolute_url(self):
"""
@@ -65,9 +67,10 @@ class ContentTypesViewsTests(TestCase):
404.
"""
for obj in Article.objects.all():
- short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk)
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
+ with self.subTest(obj=obj):
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk)
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
def test_wrong_type_pk(self):
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, 'nobody/expects')