annotate gpp/bio/tests/view_tests.py @ 552:9e42e6618168

For bitbucket issue #2, tweak the admin settings for the Post model to reduce slow queries. Define our own queryset() method so we can control the select_related(), and not have it cascade from post to topics to forums to categories. Removed 'topic' from list_display because MySQL still sucked with 2 inner joins. Now it seems to be tolerable with only one join to User.
author Brian Neal <bgneal@gmail.com>
date Wed, 25 Jan 2012 20:07:03 -0600
parents 452835f4429f
children
rev   line source
bgneal@463 1 """
bgneal@463 2 View tests for the bio application.
bgneal@463 3
bgneal@463 4 """
bgneal@463 5 import datetime
bgneal@463 6
bgneal@463 7 from django.contrib.auth.models import User
bgneal@463 8 from django.test import TestCase
bgneal@463 9 from django.core.urlresolvers import reverse, NoReverseMatch
bgneal@463 10
bgneal@463 11
bgneal@463 12 class MemberSearchTest(TestCase):
bgneal@463 13
bgneal@463 14 USERNAME = u'John'
bgneal@463 15
bgneal@463 16 def setUp(self):
bgneal@463 17 user = User.objects.create_user(self.USERNAME, '', 'password')
bgneal@463 18 user.save()
bgneal@463 19
bgneal@463 20 self.username = 'test_user'
bgneal@463 21 self.pw = 'password'
bgneal@463 22 self.user = User.objects.create_user(self.username, '', self.pw)
bgneal@463 23 self.user.save()
bgneal@463 24 self.assertTrue(self.client.login(username=self.username,
bgneal@463 25 password=self.pw))
bgneal@463 26
bgneal@463 27 def tearDown(self):
bgneal@463 28 self.client.logout()
bgneal@463 29
bgneal@463 30 def testValidName(self):
bgneal@463 31 """
bgneal@463 32 Test a valid username.
bgneal@463 33 """
bgneal@463 34
bgneal@463 35 response = self.client.post(reverse('bio-member_search'),
bgneal@463 36 {'username': self.USERNAME},
bgneal@463 37 follow=True)
bgneal@463 38
bgneal@463 39 self.assertEqual(len(response.redirect_chain), 1)
bgneal@463 40 if response.redirect_chain:
bgneal@463 41 self.assertEqual(response.redirect_chain[0][0],
bgneal@463 42 'http://testserver' + reverse('bio-view_profile',
bgneal@463 43 kwargs={'username': self.USERNAME}))
bgneal@463 44 self.assertEqual(response.redirect_chain[0][1], 302)
bgneal@463 45
bgneal@463 46 self.assertEqual(response.status_code, 200)
bgneal@463 47
bgneal@463 48 def testInvalidName(self):
bgneal@463 49 """
bgneal@463 50 Test a invalid username.
bgneal@463 51 """
bgneal@463 52
bgneal@463 53 response = self.client.post(reverse('bio-member_search'),
bgneal@463 54 {'username': self.USERNAME + '!'})
bgneal@463 55
bgneal@463 56 self.assertEqual(response.status_code, 200)
bgneal@463 57 self.assertContains(response, "That username does not exist.")
bgneal@463 58
bgneal@463 59 def testTrailingSpace(self):
bgneal@463 60 """
bgneal@463 61 Test a username with a trailing space.
bgneal@463 62 """
bgneal@463 63
bgneal@463 64 try:
bgneal@463 65 response = self.client.post(reverse('bio-member_search'),
bgneal@463 66 {'username': self.USERNAME + ' '},
bgneal@463 67 follow=True)
bgneal@463 68 except NoReverseMatch:
bgneal@463 69 self.fail('bit by a MySQL bug?')
bgneal@463 70
bgneal@463 71 self.assertEqual(len(response.redirect_chain), 1)
bgneal@463 72 if response.redirect_chain:
bgneal@463 73 self.assertEqual(response.redirect_chain[0][0],
bgneal@463 74 'http://testserver' + reverse('bio-view_profile',
bgneal@463 75 kwargs={'username': self.USERNAME}))
bgneal@463 76 self.assertEqual(response.redirect_chain[0][1], 302)
bgneal@463 77
bgneal@463 78 self.assertEqual(response.status_code, 200)