Mercurial > public > sg101
comparison potd/tests/test_tasks.py @ 1208:5c8a38122e24 modernize tip
Add unit test for POTD tasks.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 28 Jan 2025 19:02:18 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1207:80f206a12027 | 1208:5c8a38122e24 |
---|---|
1 """ | |
2 Unit tests for the potd application tasks. | |
3 | |
4 """ | |
5 from django.test import TestCase | |
6 | |
7 from potd.models import Current, Photo, Sequence | |
8 from potd.tasks import pick_potd | |
9 | |
10 | |
11 class PickPotdTestCase(TestCase): | |
12 """Testing the pick_potd celery task.""" | |
13 fixtures = ['potd_test.json'] | |
14 | |
15 def test_picks_the_next_photo_in_sequence(self): | |
16 task = pick_potd.s().apply() | |
17 current_id = Current.objects.get_current_id() | |
18 self.assertEqual(current_id, 2) | |
19 | |
20 new_photo = Photo.objects.get(pk=2) | |
21 self.assertEqual(new_photo.potd_count, 6) | |
22 | |
23 def test_generates_a_new_sequence(self): | |
24 current = Current.objects.get(pk=1) | |
25 new_photo = Photo.objects.get(pk=3) | |
26 current.potd = new_photo | |
27 current.save() | |
28 | |
29 task = pick_potd.s().apply() | |
30 | |
31 # The sequence gets shuffled, but there is a good chance it | |
32 # might be the same, so don't test that. | |
33 | |
34 current_photo = Current.objects.get_current_photo() | |
35 new_seq = Sequence.objects.get(pk=1).seq.split(',') | |
36 self.assertEqual(len(new_seq), 3) | |
37 self.assertEqual(int(new_seq[0]), current_photo.pk) | |
38 | |
39 if current_photo.pk == 1 or current_photo.pk == 3: | |
40 self.assertEqual(current_photo.potd_count, 7) | |
41 elif current_photo.pk == 2: | |
42 self.assertEqual(current_photo.potd_count, 6) | |
43 else: | |
44 self.fail('Unexpected photo pk in new sequence') | |
45 |