diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-05-10 11:27:59 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-05-10 11:27:59 +0000 |
| commit | 5c68ab6e2902b3cf67456d080c5314d3696d43e8 (patch) | |
| tree | 42cd5f75c85da51791fa8bfafd8ff41e80911b47 /tests/modeltests/test_client/models.py | |
| parent | 606f387f4942ccb76a79eecd5b9c946f6455e219 (diff) | |
Added configurable arguments to assertRedirects and assertContains to allow for other response status codes. Thanks for the suggestion, Jiri Barton.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5179 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/test_client/models.py')
| -rw-r--r-- | tests/modeltests/test_client/models.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 34242ee0d8..c36b435e25 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -35,7 +35,7 @@ class ClientTest(TestCase): self.assertEqual(response.template.name, 'GET Template') def test_no_template_view(self): - "Check that template usage assersions work then templates aren't in use" + "Template usage assertions work then templates aren't in use" response = self.client.get('/test_client/no_template_view/') # Check that the no template case doesn't mess with the template assertions @@ -75,6 +75,7 @@ class ClientTest(TestCase): self.failUnless('Data received' in response.content) def test_raw_post(self): + "POST raw data (with a content type) to a view" test_doc = """<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>""" response = self.client.post("/test_client/raw_post_view/", test_doc, content_type="text/xml") @@ -89,6 +90,28 @@ class ClientTest(TestCase): # Check that the response was a 302 (redirect) self.assertRedirects(response, '/test_client/get_view/') + def test_permanent_redirect(self): + "GET a URL that redirects permanently elsewhere" + response = self.client.get('/test_client/permanent_redirect_view/') + + # Check that the response was a 301 (permanent redirect) + self.assertRedirects(response, '/test_client/get_view/', status_code=301) + + def test_redirect_to_strange_location(self): + "GET a URL that redirects to a non-200 page" + response = self.client.get('/test_client/double_redirect_view/') + + # Check that the response was a 302, and that + # the attempt to get the redirection location returned 301 when retrieved + self.assertRedirects(response, '/test_client/permanent_redirect_view/', target_status_code=301) + + def test_notfound_response(self): + "GET a URL that responds as '404:Not Found'" + response = self.client.get('/test_client/bad_view/') + + # Check that the response was a 404, and that the content contains MAGIC + self.assertContains(response, 'MAGIC', status_code=404) + def test_valid_form(self): "POST valid data to a form" post_data = { |
