comparison bio/tests/test_views.py @ 765:f01bc9500aef

Added some more tests for the bio application.
author Brian Neal <bgneal@gmail.com>
date Sun, 19 Jan 2014 17:23:07 -0600
parents 8789299c75b1
children 22d158ef2217
comparison
equal deleted inserted replaced
764:87490b87c076 765:f01bc9500aef
3 3
4 """ 4 """
5 from django.contrib.auth.models import User 5 from django.contrib.auth.models import User
6 from django.test import TestCase 6 from django.test import TestCase
7 from django.core.urlresolvers import reverse, NoReverseMatch 7 from django.core.urlresolvers import reverse, NoReverseMatch
8 from django.http import Http404
8 9
9 10
10 class MemberSearchTest(TestCase): 11 class MemberSearchTest(TestCase):
11 12
12 USERNAME = u'John' 13 USERNAME = u'John'
72 'http://testserver' + reverse('bio-view_profile', 73 'http://testserver' + reverse('bio-view_profile',
73 kwargs={'username': self.USERNAME})) 74 kwargs={'username': self.USERNAME}))
74 self.assertEqual(response.redirect_chain[0][1], 302) 75 self.assertEqual(response.redirect_chain[0][1], 302)
75 76
76 self.assertEqual(response.status_code, 200) 77 self.assertEqual(response.status_code, 200)
78
79
80 class AnonMemberListTest(TestCase):
81
82 def _test_login_required(self, list_by):
83
84 member_list_url = reverse('bio-member_list', kwargs={'type': list_by})
85 response = self.client.get(member_list_url, follow=True)
86 login_url = reverse('accounts-login') + '?next=' + member_list_url
87 self.assertRedirects(response, login_url)
88
89 def test_login_required(self):
90 self._test_login_required('user')
91 self._test_login_required('date')
92
93
94 class MemberListTest(TestCase):
95
96 def setUp(self):
97 u1 = User.objects.create_user('paul', '', 'pw')
98 u1.save()
99 u2 = User.objects.create_user('eddie', '', 'pw')
100 u2.save()
101
102 self.user = u1
103 self.client.login(username=u1.username, password='pw')
104
105 def _test_get(self, list_by, page=None, code=200):
106
107 member_list_url = reverse('bio-member_list', kwargs={'type': list_by})
108 if page is not None:
109 member_list_url += '?page=%d' % page
110 response = self.client.get(member_list_url)
111 self.assertEqual(response.status_code, code)
112
113 def test_get(self):
114 self._test_get('user')
115 self._test_get('date')
116 self._test_get('user', page=1)
117 self._test_get('date', page=1)
118
119 def test_invalid_page(self):
120 self._test_get('user', page=99, code=404)
121 self._test_get('date', page=99, code=404)
122
123
124 class MyProfileTest(TestCase):
125
126 def setUp(self):
127 u1 = User.objects.create_user('paul', '', 'pw')
128 u1.save()
129 u2 = User.objects.create_user('eddie', '', 'pw')
130 u2.save()
131
132 def test_anon(self):
133 my_url = reverse('bio-me')
134 response = self.client.get(my_url)
135 login_url = reverse('accounts-login') + '?next=' + my_url
136 self.assertRedirects(response, login_url)
137
138 def test_authenticated(self):
139 self.client.login(username='paul', password='pw')
140 response = self.client.get(reverse('bio-me'))
141 self.assertEqual(response.status_code, 200)