comparison bio/tests/test_views.py @ 744:8789299c75b1

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