diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-05-05 03:03:33 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-05-05 03:03:33 +0000 |
| commit | a0ef3ba2f7e815b4f3617f6e2827f66c13de3194 (patch) | |
| tree | 5f2289eaef2d65c8c5bdc43b4632c57da2de342c /tests/modeltests/test_client | |
| parent | e986e8aba4d301c2be2b3a2607ee57e7de2fb494 (diff) | |
Added a default test Client to TestCase, and added some assertions for some common testing patterns.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5150 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/test_client')
| -rw-r--r-- | tests/modeltests/test_client/models.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 44ddffb55f..58f1d47e50 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -24,19 +24,14 @@ from django.test import Client, TestCase class ClientTest(TestCase): fixtures = ['testdata.json'] - def setUp(self): - "Set up test environment" - self.client = Client() - def test_get_view(self): "GET a view" response = self.client.get('/test_client/get_view/') # Check some response details - self.assertEqual(response.status_code, 200) + self.assertContains(response, 'This is a test') self.assertEqual(response.context['var'], 42) self.assertEqual(response.template.name, 'GET Template') - self.failUnless('This is a test.' in response.content) def test_get_post_view(self): "GET a view that normally expects POSTs" @@ -80,7 +75,7 @@ class ClientTest(TestCase): response = self.client.get('/test_client/redirect_view/') # Check that the response was a 302 (redirect) - self.assertEqual(response.status_code, 302) + self.assertRedirects(response, '/test_client/get_view/') def test_valid_form(self): "POST valid data to a form" @@ -102,7 +97,7 @@ class ClientTest(TestCase): 'value': 37 } response = self.client.post('/test_client/form_view/', post_data) - self.assertEqual(response.status_code, 200) + self.assertContains(response, 'This field is required', 3) self.assertEqual(response.template.name, "Invalid POST Template") def test_form_error(self): @@ -130,7 +125,7 @@ class ClientTest(TestCase): # Get the page without logging in. Should result in 302. response = self.client.get('/test_client/login_protected_view/') - self.assertEqual(response.status_code, 302) + self.assertRedirects(response, '/accounts/login/') # Request a page that requires a login response = self.client.login('/test_client/login_protected_view/', 'testclient', 'password') |
