diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-03-14 20:28:24 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-03-14 20:30:23 +0100 |
| commit | 3f2befc93163e0666dcc4f745288b98306de4b8e (patch) | |
| tree | ecca16348da0fab7c87bba937090aef498c9ff2f /tests/contenttypes_tests/tests.py | |
| parent | 2f121dfe635b3f497fe1fe03bc8eb97cdf5083b3 (diff) | |
Deprecated django.views.defaults.shortcut.
Diffstat (limited to 'tests/contenttypes_tests/tests.py')
| -rw-r--r-- | tests/contenttypes_tests/tests.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py new file mode 100644 index 0000000000..b39e118ec6 --- /dev/null +++ b/tests/contenttypes_tests/tests.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import, unicode_literals + +from django.contrib.contenttypes.models import ContentType +from django.test import TestCase + +from .models import Author, Article + +class ContentTypesViewsTests(TestCase): + fixtures = ['testdata.json'] + urls = 'contenttypes_tests.urls' + + 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(), + status_code=302, target_status_code=404) + + def test_shortcut_no_absolute_url(self): + "Shortcuts for an object that has no get_absolute_url method raises 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) + + def test_wrong_type_pk(self): + short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, 'nobody/expects') + response = self.client.get(short_url) + self.assertEqual(response.status_code, 404) + + def test_shortcut_bad_pk(self): + short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, '42424242') + response = self.client.get(short_url) + self.assertEqual(response.status_code, 404) + + def test_nonint_content_type(self): + an_author = Author.objects.all()[0] + short_url = '/shortcut/%s/%s/' % ('spam', an_author.pk) + response = self.client.get(short_url) + self.assertEqual(response.status_code, 404) + + def test_bad_content_type(self): + an_author = Author.objects.all()[0] + short_url = '/shortcut/%s/%s/' % (42424242, an_author.pk) + response = self.client.get(short_url) + self.assertEqual(response.status_code, 404) |
