bgneal@1208: """ bgneal@1208: Unit tests for the potd application tasks. bgneal@1208: bgneal@1208: """ bgneal@1208: from django.test import TestCase bgneal@1208: bgneal@1208: from potd.models import Current, Photo, Sequence bgneal@1208: from potd.tasks import pick_potd bgneal@1208: bgneal@1208: bgneal@1208: class PickPotdTestCase(TestCase): bgneal@1208: """Testing the pick_potd celery task.""" bgneal@1208: fixtures = ['potd_test.json'] bgneal@1208: bgneal@1208: def test_picks_the_next_photo_in_sequence(self): bgneal@1208: task = pick_potd.s().apply() bgneal@1208: current_id = Current.objects.get_current_id() bgneal@1208: self.assertEqual(current_id, 2) bgneal@1208: bgneal@1208: new_photo = Photo.objects.get(pk=2) bgneal@1208: self.assertEqual(new_photo.potd_count, 6) bgneal@1208: bgneal@1208: def test_generates_a_new_sequence(self): bgneal@1208: current = Current.objects.get(pk=1) bgneal@1208: new_photo = Photo.objects.get(pk=3) bgneal@1208: current.potd = new_photo bgneal@1208: current.save() bgneal@1208: bgneal@1208: task = pick_potd.s().apply() bgneal@1208: bgneal@1208: # The sequence gets shuffled, but there is a good chance it bgneal@1208: # might be the same, so don't test that. bgneal@1208: bgneal@1208: current_photo = Current.objects.get_current_photo() bgneal@1208: new_seq = Sequence.objects.get(pk=1).seq.split(',') bgneal@1208: self.assertEqual(len(new_seq), 3) bgneal@1208: self.assertEqual(int(new_seq[0]), current_photo.pk) bgneal@1208: bgneal@1208: if current_photo.pk == 1 or current_photo.pk == 3: bgneal@1208: self.assertEqual(current_photo.potd_count, 7) bgneal@1208: elif current_photo.pk == 2: bgneal@1208: self.assertEqual(current_photo.potd_count, 6) bgneal@1208: else: bgneal@1208: self.fail('Unexpected photo pk in new sequence') bgneal@1208: