Mercurial > public > sg101
comparison bio/tests/view_tests.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/bio/tests/view_tests.py@452835f4429f |
children |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 View tests for the bio application. | |
3 | |
4 """ | |
5 import datetime | |
6 | |
7 from django.contrib.auth.models import User | |
8 from django.test import TestCase | |
9 from django.core.urlresolvers import reverse, NoReverseMatch | |
10 | |
11 | |
12 class MemberSearchTest(TestCase): | |
13 | |
14 USERNAME = u'John' | |
15 | |
16 def setUp(self): | |
17 user = User.objects.create_user(self.USERNAME, '', 'password') | |
18 user.save() | |
19 | |
20 self.username = 'test_user' | |
21 self.pw = 'password' | |
22 self.user = User.objects.create_user(self.username, '', self.pw) | |
23 self.user.save() | |
24 self.assertTrue(self.client.login(username=self.username, | |
25 password=self.pw)) | |
26 | |
27 def tearDown(self): | |
28 self.client.logout() | |
29 | |
30 def testValidName(self): | |
31 """ | |
32 Test a valid username. | |
33 """ | |
34 | |
35 response = self.client.post(reverse('bio-member_search'), | |
36 {'username': self.USERNAME}, | |
37 follow=True) | |
38 | |
39 self.assertEqual(len(response.redirect_chain), 1) | |
40 if response.redirect_chain: | |
41 self.assertEqual(response.redirect_chain[0][0], | |
42 'http://testserver' + reverse('bio-view_profile', | |
43 kwargs={'username': self.USERNAME})) | |
44 self.assertEqual(response.redirect_chain[0][1], 302) | |
45 | |
46 self.assertEqual(response.status_code, 200) | |
47 | |
48 def testInvalidName(self): | |
49 """ | |
50 Test a invalid username. | |
51 """ | |
52 | |
53 response = self.client.post(reverse('bio-member_search'), | |
54 {'username': self.USERNAME + '!'}) | |
55 | |
56 self.assertEqual(response.status_code, 200) | |
57 self.assertContains(response, "That username does not exist.") | |
58 | |
59 def testTrailingSpace(self): | |
60 """ | |
61 Test a username with a trailing space. | |
62 """ | |
63 | |
64 try: | |
65 response = self.client.post(reverse('bio-member_search'), | |
66 {'username': self.USERNAME + ' '}, | |
67 follow=True) | |
68 except NoReverseMatch: | |
69 self.fail('bit by a MySQL bug?') | |
70 | |
71 self.assertEqual(len(response.redirect_chain), 1) | |
72 if response.redirect_chain: | |
73 self.assertEqual(response.redirect_chain[0][0], | |
74 'http://testserver' + reverse('bio-view_profile', | |
75 kwargs={'username': self.USERNAME})) | |
76 self.assertEqual(response.redirect_chain[0][1], 302) | |
77 | |
78 self.assertEqual(response.status_code, 200) |