bgneal@933: """Tests for potd signal handlers.""" bgneal@933: from django.contrib.auth.models import User bgneal@933: from django.test import TestCase bgneal@933: bgneal@933: from mock import Mock bgneal@933: bgneal@933: from potd.models import Photo, Sequence, Current bgneal@933: bgneal@933: bgneal@933: class PotdSignalRcvrTestCase(TestCase): bgneal@933: bgneal@933: fixtures = ['potd_test.json'] bgneal@933: bgneal@933: def test_on_photo_save(self): bgneal@933: user = User.objects.get(pk=1) bgneal@933: photo = Photo(photo='/tmp/1.jpg', bgneal@933: caption='caption', bgneal@933: description='desc', bgneal@933: user=user) bgneal@933: photo.generate_thumb = Mock() bgneal@933: photo.save() bgneal@933: bgneal@933: current = Current.objects.get_current_id() bgneal@933: self.assertTrue(current != photo.pk) bgneal@933: bgneal@933: seq = Sequence.objects.get(pk=1) bgneal@933: expected = '1,{},2,3'.format(photo.pk) bgneal@933: self.assertEqual(seq.seq, expected) bgneal@933: bgneal@933: def test_on_photo_delete(self): bgneal@933: photo = Photo.objects.get(pk=2) bgneal@933: photo.delete() bgneal@933: seq = Sequence.objects.get(pk=1) bgneal@933: self.assertEqual(seq.seq, '1,3')