annotate gpp/potd/tests/tools_tests.py @ 515:ae89ba801e8b

For #194, convert the POTD management command to a celery task. Refactored to put the logic for the command into a function, and the command simply calls this function. The task can also just call this function. Added some basic tests for the new function.
author Brian Neal <bgneal@gmail.com>
date Wed, 14 Dec 2011 02:41:15 +0000
parents
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]))