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