diff options
| author | Thomas Sorrel <thomas@pandeiro.fr> | 2014-03-02 21:46:51 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2014-03-03 22:57:06 +0100 |
| commit | 53c576452e2e8feef857cd67a5c17f9159d95eb6 (patch) | |
| tree | 85e1a9f0fb60994a4743399684e4b65bd806bd9b /tests/contenttypes_tests | |
| parent | 7bbb6958dcb6a450f926e5bb49b07391f801aef1 (diff) | |
Fixed #16727 -- Added protocol-relative URL support to contenttypes.views.shortcut.
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/fixtures/testdata.json | 21 | ||||
| -rw-r--r-- | tests/contenttypes_tests/models.py | 11 | ||||
| -rw-r--r-- | tests/contenttypes_tests/tests.py | 15 |
3 files changed, 46 insertions, 1 deletions
diff --git a/tests/contenttypes_tests/fixtures/testdata.json b/tests/contenttypes_tests/fixtures/testdata.json index 52510bfe90..114b1e262f 100644 --- a/tests/contenttypes_tests/fixtures/testdata.json +++ b/tests/contenttypes_tests/fixtures/testdata.json @@ -38,6 +38,27 @@ }, { "pk": 1, + "model": "contenttypes_tests.schemeincludedurl", + "fields": { + "url": "http://test_scheme_included_http/" + } + }, + { + "pk": 2, + "model": "contenttypes_tests.schemeincludedurl", + "fields": { + "url": "https://test_scheme_included_https/" + } + }, + { + "pk": 3, + "model": "contenttypes_tests.schemeincludedurl", + "fields": { + "url": "//test_default_scheme_kept/" + } + }, + { + "pk": 1, "model": "sites.site", "fields": { "domain": "testserver", diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py index d47cfac7f7..dadc40d3d9 100644 --- a/tests/contenttypes_tests/models.py +++ b/tests/contenttypes_tests/models.py @@ -24,3 +24,14 @@ class Article(models.Model): def __str__(self): return self.title + + +@python_2_unicode_compatible +class SchemeIncludedURL(models.Model): + url = models.URLField(max_length=100) + + def __str__(self): + return self.url + + def get_absolute_url(self): + return self.url diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index af2cedd8b3..085ad2ec89 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -12,7 +12,7 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils.encoding import force_str -from .models import Author, Article +from .models import Author, Article, SchemeIncludedURL class ContentTypesViewsTests(TestCase): @@ -27,6 +27,19 @@ class ContentTypesViewsTests(TestCase): self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(), status_code=302, target_status_code=404) + def test_shortcut_with_absolute_url_including_scheme(self): + """ + Can view a shortcut when object's get_absolute_url returns a full URL + the tested URLs are in fixtures/testdata.json : + "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(), + status_code=302, + fetch_redirect_response=False) + 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(): |
