bgneal@1208
|
1 """
|
bgneal@1208
|
2 Unit tests for the potd application tasks.
|
bgneal@1208
|
3
|
bgneal@1208
|
4 """
|
bgneal@1208
|
5 from django.test import TestCase
|
bgneal@1208
|
6
|
bgneal@1208
|
7 from potd.models import Current, Photo, Sequence
|
bgneal@1208
|
8 from potd.tasks import pick_potd
|
bgneal@1208
|
9
|
bgneal@1208
|
10
|
bgneal@1208
|
11 class PickPotdTestCase(TestCase):
|
bgneal@1208
|
12 """Testing the pick_potd celery task."""
|
bgneal@1208
|
13 fixtures = ['potd_test.json']
|
bgneal@1208
|
14
|
bgneal@1208
|
15 def test_picks_the_next_photo_in_sequence(self):
|
bgneal@1208
|
16 task = pick_potd.s().apply()
|
bgneal@1208
|
17 current_id = Current.objects.get_current_id()
|
bgneal@1208
|
18 self.assertEqual(current_id, 2)
|
bgneal@1208
|
19
|
bgneal@1208
|
20 new_photo = Photo.objects.get(pk=2)
|
bgneal@1208
|
21 self.assertEqual(new_photo.potd_count, 6)
|
bgneal@1208
|
22
|
bgneal@1208
|
23 def test_generates_a_new_sequence(self):
|
bgneal@1208
|
24 current = Current.objects.get(pk=1)
|
bgneal@1208
|
25 new_photo = Photo.objects.get(pk=3)
|
bgneal@1208
|
26 current.potd = new_photo
|
bgneal@1208
|
27 current.save()
|
bgneal@1208
|
28
|
bgneal@1208
|
29 task = pick_potd.s().apply()
|
bgneal@1208
|
30
|
bgneal@1208
|
31 # The sequence gets shuffled, but there is a good chance it
|
bgneal@1208
|
32 # might be the same, so don't test that.
|
bgneal@1208
|
33
|
bgneal@1208
|
34 current_photo = Current.objects.get_current_photo()
|
bgneal@1208
|
35 new_seq = Sequence.objects.get(pk=1).seq.split(',')
|
bgneal@1208
|
36 self.assertEqual(len(new_seq), 3)
|
bgneal@1208
|
37 self.assertEqual(int(new_seq[0]), current_photo.pk)
|
bgneal@1208
|
38
|
bgneal@1208
|
39 if current_photo.pk == 1 or current_photo.pk == 3:
|
bgneal@1208
|
40 self.assertEqual(current_photo.potd_count, 7)
|
bgneal@1208
|
41 elif current_photo.pk == 2:
|
bgneal@1208
|
42 self.assertEqual(current_photo.potd_count, 6)
|
bgneal@1208
|
43 else:
|
bgneal@1208
|
44 self.fail('Unexpected photo pk in new sequence')
|
bgneal@1208
|
45
|