comparison 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
comparison
equal deleted inserted replaced
514:6d816aa586c1 515:ae89ba801e8b
1 """
2 Tests for the pick_potd() function.
3
4 """
5 from django.test import TestCase
6 from django.contrib.auth.models import User
7
8 from potd.models import Current, Photo, Sequence
9 from potd.tools import pick_potd
10
11
12 class PickPotdTest(TestCase):
13
14 fixtures = ['potd_test.json']
15
16 def test_pick(self):
17
18 pick_potd()
19
20 curr = Current.objects.get(pk=1)
21 self.assertEqual(curr.potd.pk, 2)
22
23 def test_shuffle(self):
24
25 photo = Photo.objects.get(pk=3)
26 curr = Current.objects.get(pk=1)
27 curr.potd = photo
28 curr.save()
29
30 pick_potd()
31
32 ids = Sequence.objects.get(pk=1).seq.split(',')
33 curr = Current.objects.get(pk=1)
34 self.assertEqual(len(ids), 3)
35 self.assertEqual(curr.potd.pk, int(ids[0]))