예제 #1
0
def offer_update_published(sender, instance, raw, **kwargs):
    if instance.pk is not None:
        if instance.status == Offer.PUBLISHED:
            old_instance = Offer.objects.get(pk=instance.pk)
            if old_instance.status == Offer.UNPUBLISHED:
                instance.published_at = timezone.now()

                if not instance.is_request:
                    from offers.tasks import publish_offer
                    publish_offer.delay(instance.pk)
        elif instance.is_ready:
            old_instance = Offer.objects.get(pk=instance.pk)
            if not old_instance.is_ready:
                # Comment became ready
                instance.readied_at = timezone.now()
예제 #2
0
    def test_publish_offer_does_nothing_with_invalid_offer(self):
        """
        Test that the publish_offer task does nothing with an invalid (unpublished) offer
        """
        self.offer.is_request = True
        self.offer.save()

        self.assertEqual(self.offer.followers.count(), 0)

        result = publish_offer.delay(self.offer.pk)

        self.assertTrue(result.successful())

        self.assertNotIn(self.user, self.offer.followers.all())
        self.assertEqual(self.offer.followers.count(), 0)
        self.assertEqual(len(mail.outbox), 0)
예제 #3
0
    def test_publish_offer_adds_provider_as_follower(self):
        """
        Test that the publish_offer task adds all users who manage a provider as followers
        """
        self.assertEqual(self.offer.followers.count(), 0)

        result = publish_offer.delay(self.offer.pk)

        self.assertTrue(result.successful())

        self.assertIn(self.user, self.offer.followers.all())
        self.assertEqual(self.offer.followers.count(), 1)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].to), 1)
        self.assertEqual(mail.outbox[0].to[0], self.user.email)
예제 #4
0
    def test_publish_offer_does_nothing_with_invalid_offer(self):
        """
        Test that the publish_offer task does nothing with an invalid (unpublished) offer
        """
        self.offer.is_request = True
        self.offer.save()

        self.assertEqual(self.offer.followers.count(), 0)

        result = publish_offer.delay(self.offer.pk)

        self.assertTrue(result.successful())

        self.assertNotIn(self.user, self.offer.followers.all())
        self.assertEqual(self.offer.followers.count(), 0)
        self.assertEqual(len(mail.outbox), 0)
예제 #5
0
    def test_publish_offer_adds_provider_as_follower(self):
        """
        Test that the publish_offer task adds all users who manage a provider as followers
        """
        self.assertEqual(self.offer.followers.count(), 0)

        result = publish_offer.delay(self.offer.pk)

        self.assertTrue(result.successful())

        self.assertIn(self.user, self.offer.followers.all())
        self.assertEqual(self.offer.followers.count(), 1)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].to), 1)
        self.assertEqual(mail.outbox[0].to[0], self.user.email)