# HG changeset patch # User Brian Neal # Date 1390173787 21600 # Node ID f01bc9500aef16fbf2c85479d6b0b35815941c62 # Parent 87490b87c076e8cbc204b57587444b1642bc19ef Added some more tests for the bio application. diff -r 87490b87c076 -r f01bc9500aef bio/tests/test_views.py --- a/bio/tests/test_views.py Sun Jan 19 17:22:49 2014 -0600 +++ b/bio/tests/test_views.py Sun Jan 19 17:23:07 2014 -0600 @@ -5,6 +5,7 @@ from django.contrib.auth.models import User from django.test import TestCase from django.core.urlresolvers import reverse, NoReverseMatch +from django.http import Http404 class MemberSearchTest(TestCase): @@ -74,3 +75,67 @@ self.assertEqual(response.redirect_chain[0][1], 302) self.assertEqual(response.status_code, 200) + + +class AnonMemberListTest(TestCase): + + def _test_login_required(self, list_by): + + member_list_url = reverse('bio-member_list', kwargs={'type': list_by}) + response = self.client.get(member_list_url, follow=True) + login_url = reverse('accounts-login') + '?next=' + member_list_url + self.assertRedirects(response, login_url) + + def test_login_required(self): + self._test_login_required('user') + self._test_login_required('date') + + +class MemberListTest(TestCase): + + def setUp(self): + u1 = User.objects.create_user('paul', '', 'pw') + u1.save() + u2 = User.objects.create_user('eddie', '', 'pw') + u2.save() + + self.user = u1 + self.client.login(username=u1.username, password='pw') + + def _test_get(self, list_by, page=None, code=200): + + member_list_url = reverse('bio-member_list', kwargs={'type': list_by}) + if page is not None: + member_list_url += '?page=%d' % page + response = self.client.get(member_list_url) + self.assertEqual(response.status_code, code) + + def test_get(self): + self._test_get('user') + self._test_get('date') + self._test_get('user', page=1) + self._test_get('date', page=1) + + def test_invalid_page(self): + self._test_get('user', page=99, code=404) + self._test_get('date', page=99, code=404) + + +class MyProfileTest(TestCase): + + def setUp(self): + u1 = User.objects.create_user('paul', '', 'pw') + u1.save() + u2 = User.objects.create_user('eddie', '', 'pw') + u2.save() + + def test_anon(self): + my_url = reverse('bio-me') + response = self.client.get(my_url) + login_url = reverse('accounts-login') + '?next=' + my_url + self.assertRedirects(response, login_url) + + def test_authenticated(self): + self.client.login(username='paul', password='pw') + response = self.client.get(reverse('bio-me')) + self.assertEqual(response.status_code, 200)