def testPublishedSignal(self): book = models.Book.objects.get(pk=1) self.name = None # define the local listener def published_listener(sender, instance, **kwargs): self.name = instance.name # connect & send the signal published_signal.connect(published_listener) book.publish() self.assertEqual(self.name, book.name) base_book = models.BookBase.objects.get(pk=1) self.assertEqual(book.last_scheduled, base_book.v_last_save)
def testPublishedFutureNoSignal(self): book = models.Book.objects.get(pk=1) # define the local listener def published_listener(sender, instance, **kwargs): assert False, "Should not have been called" # connect & send the signal published_signal.connect(published_listener) book.publish(when=timezone.now() + datetime.timedelta(hours=1)) self.assertTrue(book.state, models.Book.SCHEDULED) base_book = models.BookBase.objects.get(pk=1) self.assertFalse(book.last_scheduled == base_book.v_last_save) self.assertTrue(models.Book.objects.filter(object_id=book.object_id, state=models.Book.SCHEDULED).exists()) self.assertFalse(models.Book.objects.filter(object_id=book.object_id, state=models.Book.PUBLISHED).exists())