annotate potd/tests/tools_tests.py @ 629:f4c043cf55ac

Wiki integration. Requests don't always have sessions. In particular this occurs when a request is made without a trailing slash. The Common middleware redirects when this happens, and the middleware process_request() processing stops before a session can get added. So just set an attribute on the request object for each operation. This seemed weird to me at first, but there are plenty of examples of this in the Django code base already.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Nov 2012 13:50:06 -0600
parents ee87ea74d46b
children
rev   line source
bgneal@515 1 """
bgneal@515 2 Tests for the pick_potd() function.
bgneal@515 3
bgneal@515 4 """
bgneal@515 5 from django.test import TestCase
bgneal@515 6 from django.contrib.auth.models import User
bgneal@515 7
bgneal@515 8 from potd.models import Current, Photo, Sequence
bgneal@515 9 from potd.tools import pick_potd
bgneal@515 10
bgneal@515 11
bgneal@515 12 class PickPotdTest(TestCase):
bgneal@515 13
bgneal@515 14 fixtures = ['potd_test.json']
bgneal@515 15
bgneal@515 16 def test_pick(self):
bgneal@515 17
bgneal@515 18 pick_potd()
bgneal@515 19
bgneal@515 20 curr = Current.objects.get(pk=1)
bgneal@515 21 self.assertEqual(curr.potd.pk, 2)
bgneal@515 22
bgneal@515 23 def test_shuffle(self):
bgneal@515 24
bgneal@515 25 photo = Photo.objects.get(pk=3)
bgneal@515 26 curr = Current.objects.get(pk=1)
bgneal@515 27 curr.potd = photo
bgneal@515 28 curr.save()
bgneal@515 29
bgneal@515 30 pick_potd()
bgneal@515 31
bgneal@515 32 ids = Sequence.objects.get(pk=1).seq.split(',')
bgneal@515 33 curr = Current.objects.get(pk=1)
bgneal@515 34 self.assertEqual(len(ids), 3)
bgneal@515 35 self.assertEqual(curr.potd.pk, int(ids[0]))