changeset 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 87490b87c076
children 22d158ef2217
files bio/tests/test_views.py
diffstat 1 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)