Пример #1
0
    def test_publish_latest_offer_does_not_publish_empty_offers(self):
        """
        Test that publish_latest_offer does not publish any offers if there are no applicable offers
        """
        self.offer.delete()

        mommy.make(
            Offer,
            _quantity=3,
            is_ready=False,
            is_request=True,
            status=Offer.UNPUBLISHED,
        )

        mommy.make(
            Offer,
            _quantity=3,
            is_ready=True,
            is_request=False,
            status=Offer.UNPUBLISHED,
        )

        self.assertTrue(publish_latest_offer.delay().successful())
        self.assertEqual(
            Offer.objects.filter(status=Offer.PUBLISHED).count(), 0)
Пример #2
0
    def test_publish_latest_offer_publishes_oldest_offer(self):
        """
        Test that publish_latest_offer publishes the oldest offer
        """
        self.offer.delete()

        offers = mommy.make(
            Offer,
            _quantity=3,
            is_ready=True,
            is_request=True,
            status=Offer.UNPUBLISHED,
            provider=self.provider,
            creator=self.user
        )
        # Create some offers who should not be affected since they are invalid
        mommy.make(Offer, is_ready=False, is_request=True)
        mommy.make(Offer, status=Offer.PUBLISHED)

        # Set the oldest to newest
        offers[0].readied_at -= timedelta(days=3)
        offers[1].readied_at -= timedelta(days=2)
        offers[2].readied_at -= timedelta(days=1)

        self.assertTrue(publish_latest_offer.delay().successful())

        new_offer = Offer.objects.get(pk=offers[0].pk)

        self.assertEqual(new_offer.status, Offer.PUBLISHED)
        self.assertFalse(new_offer.is_request)

        self.assertEqual(Offer.objects.filter(status=Offer.PUBLISHED, is_request=False).count(), 2)
Пример #3
0
    def test_publish_latest_offer_publishes_oldest_offer(self):
        """
        Test that publish_latest_offer publishes the oldest offer
        """
        self.offer.delete()

        offers = mommy.make(Offer,
                            _quantity=3,
                            is_ready=True,
                            is_request=True,
                            status=Offer.UNPUBLISHED,
                            provider=self.provider,
                            creator=self.user)
        # Create some offers who should not be affected since they are invalid
        mommy.make(Offer, is_ready=False, is_request=True)
        mommy.make(Offer, status=Offer.PUBLISHED)

        # Set the oldest to newest
        offers[0].readied_at -= timedelta(days=3)
        offers[1].readied_at -= timedelta(days=2)
        offers[2].readied_at -= timedelta(days=1)

        self.assertTrue(publish_latest_offer.delay().successful())

        new_offer = Offer.objects.get(pk=offers[0].pk)

        self.assertEqual(new_offer.status, Offer.PUBLISHED)
        self.assertFalse(new_offer.is_request)

        self.assertEqual(
            Offer.objects.filter(status=Offer.PUBLISHED,
                                 is_request=False).count(), 2)
Пример #4
0
    def test_publish_latest_offer_does_not_publish_empty_offers(self):
        """
        Test that publish_latest_offer does not publish any offers if there are no applicable offers
        """
        self.offer.delete()

        mommy.make(
            Offer,
            _quantity=3,
            is_ready=False,
            is_request=True,
            status=Offer.UNPUBLISHED,
        )

        mommy.make(
            Offer,
            _quantity=3,
            is_ready=True,
            is_request=False,
            status=Offer.UNPUBLISHED,
        )

        self.assertTrue(publish_latest_offer.delay().successful())
        self.assertEqual(Offer.objects.filter(status=Offer.PUBLISHED).count(), 0)