summaryrefslogtreecommitdiff
path: root/tests/modeltests/test_client/models.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2007-08-26 01:10:53 +0000
committerJustin Bronn <jbronn@gmail.com>2007-08-26 01:10:53 +0000
commit2052b508eb92c62fc0678efd4936c5ec1e0e735b (patch)
treee510109b74b28c8ccef5f6955727cb9dce3da655 /tests/modeltests/test_client/models.py
parenta7297a255f4bb86f608ea251e00253d18c31d9d4 (diff)
gis: Made necessary modifications for unicode, manage refactor, backend refactor and merged 5584-6000 via svnmerge from [repos:django/trunk trunk].
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6018 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/test_client/models.py')
-rw-r--r--tests/modeltests/test_client/models.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index 5ebf29678c..e1f3987847 100644
--- a/tests/modeltests/test_client/models.py
+++ b/tests/modeltests/test_client/models.py
@@ -1,3 +1,4 @@
+# coding: utf-8
"""
38. Testing using the Test Client
@@ -27,11 +28,14 @@ class ClientTest(TestCase):
def test_get_view(self):
"GET a view"
- response = self.client.get('/test_client/get_view/')
+ # The data is ignored, but let's check it doesn't crash the system
+ # anyway.
+ data = {'var': u'\xf2'}
+ response = self.client.get('/test_client/get_view/', data)
# Check some response details
self.assertContains(response, 'This is a test')
- self.assertEqual(response.context['var'], 42)
+ self.assertEqual(response.context['var'], u'\xf2')
self.assertEqual(response.template.name, 'GET Template')
def test_get_post_view(self):
@@ -118,6 +122,18 @@ class ClientTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "Valid POST Template")
+ def test_valid_form_with_hints(self):
+ "GET a form, providing hints in the GET data"
+ hints = {
+ 'text': 'Hello World',
+ 'multi': ('b','c','e')
+ }
+ response = self.client.get('/test_client/form_view/', data=hints)
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, "Form GET Template")
+ # Check that the multi-value data has been rolled out ok
+ self.assertContains(response, 'Select a valid choice.', 0)
+
def test_incomplete_data_form(self):
"POST incomplete data to a form"
post_data = {
@@ -224,6 +240,29 @@ class ClientTest(TestCase):
login = self.client.login(username='otheruser', password='nopassword')
self.failIf(login)
+ def test_view_with_inactive_login(self):
+ "Request a page that is protected with @login, but use an inactive login"
+
+ login = self.client.login(username='inactive', password='password')
+ self.failIf(login)
+
+ def test_logout(self):
+ "Request a logout after logging in"
+ # Log in
+ self.client.login(username='testclient', password='password')
+
+ # Request a page that requires a login
+ response = self.client.get('/test_client/login_protected_view/')
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['user'].username, 'testclient')
+
+ # Log out
+ self.client.logout()
+
+ # Request a page that requires a login
+ response = self.client.get('/test_client/login_protected_view/')
+ self.assertRedirects(response, '/accounts/login/')
+
def test_session_modifying_view(self):
"Request a page that modifies the session"
# Session value isn't set initially
@@ -281,4 +320,4 @@ class ClientTest(TestCase):
self.assertEqual(mail.outbox[1].from_email, 'from@example.com')
self.assertEqual(mail.outbox[1].to[0], 'second@example.com')
self.assertEqual(mail.outbox[1].to[1], 'third@example.com')
- \ No newline at end of file
+