diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-03-21 13:09:13 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-03-21 13:09:13 +0000 |
| commit | d7e81275242a8439768367059701baa00a9be996 (patch) | |
| tree | dde63526ee8ad5d480586417dd7b6e3c411c7286 /tests/regressiontests/urlpatterns_reverse | |
| parent | 4eadcf45d4d3951cd674caebeee9c62712bef781 (diff) | |
Fixed #10194: added `django.shortcuts.redirect`, a do-what-I-mean redirect shortcut. See the docs at topics/http/shortcuts for details.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10108 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/urlpatterns_reverse')
| -rw-r--r-- | tests/regressiontests/urlpatterns_reverse/tests.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index aecfdfc6c5..b7ef0e5b9b 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -3,6 +3,8 @@ Unit tests for reverse URL lookups. """ from django.core.urlresolvers import reverse, NoReverseMatch +from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect +from django.shortcuts import redirect from django.test import TestCase test_data = ( @@ -97,3 +99,34 @@ class URLPatternReverse(TestCase): else: self.assertEquals(got, expected) +class ReverseShortcutTests(TestCase): + urls = 'regressiontests.urlpatterns_reverse.urls' + + def test_redirect_to_object(self): + # We don't really need a model; just something with a get_absolute_url + class FakeObj(object): + def get_absolute_url(self): + return "/hi-there/" + + res = redirect(FakeObj()) + self.assert_(isinstance(res, HttpResponseRedirect)) + self.assertEqual(res['Location'], '/hi-there/') + + res = redirect(FakeObj(), permanent=True) + self.assert_(isinstance(res, HttpResponsePermanentRedirect)) + self.assertEqual(res['Location'], '/hi-there/') + + def test_redirect_to_view_name(self): + res = redirect('hardcoded2') + self.assertEqual(res['Location'], '/hardcoded/doc.pdf') + res = redirect('places', 1) + self.assertEqual(res['Location'], '/places/1/') + res = redirect('headlines', year='2008', month='02', day='17') + self.assertEqual(res['Location'], '/headlines/2008.02.17/') + self.assertRaises(NoReverseMatch, redirect, 'not-a-view') + + def test_redirect_to_url(self): + res = redirect('/foo/') + self.assertEqual(res['Location'], '/foo/') + res = redirect('http://example.com/') + self.assertEqual(res['Location'], 'http://example.com/')
\ No newline at end of file |
