def test_get_offers_with_bundle(self):
        """ Verify that only offers related to the bundle id are returned. """
        program_offers = [ProgramOfferFactory()]
        bundle_id = program_offers[0].condition.program_uuid
        self.create_bundle_attribute(bundle_id)

        ConditionalOfferFactory.create_batch(2)  # Unrelated offers that should not be returned

        self.applicator.get_site_offers = mock.Mock()
        self.assert_correct_offers(program_offers)
        self.assertFalse(self.applicator.get_site_offers.called)  # Verify there was no attempt to get all site offers
    def test_get_offers_without_bundle(self):
        """ Verify that all non bundle offers are returned if no bundle id is given. """
        offers_in_db = list(
            ConditionalOffer.active.filter(offer_type=ConditionalOffer.SITE))
        site_offers = ConditionalOfferFactory.create_batch(3) + offers_in_db
        ProgramOfferFactory()

        # Verify that program offer was not returned without bundle_id
        self.assert_correct_offers(site_offers)
示例#3
0
    def test_get_offers_without_bundle(self):
        """ Verify that all offers are returned if no bundle id is given. """
        site_offers = ConditionalOfferFactory.create_batch(3)

        self.applicator.get_program_offers = mock.Mock()

        self.assert_correct_offers(site_offers)

        self.assertFalse(self.applicator.get_program_offers.called
                         )  # Verify there was no attempt to match off a bundle
示例#4
0
    def test_get_offers_without_bundle(self):
        """ Verify that all non bundle offers are returned if no bundle id is given. """
        offers_in_db = list(
            ConditionalOffer.active.filter(offer_type=ConditionalOffer.SITE))
        ProgramOfferFactory()
        site_offers = ConditionalOfferFactory.create_batch(3) + offers_in_db

        self.applicator.get_program_offers = mock.Mock()

        self.assert_correct_offers(site_offers)

        self.assertFalse(self.applicator.get_program_offers.called
                         )  # Verify there was no attempt to match off a bundle
示例#5
0
    def test_log_is_fired_when_get_offers_without_bundle(self):
        """ Verify that logs are fired when no bundle id is given but offers are being applied"""
        site_offers = ConditionalOfferFactory.create_batch(3)

        self.applicator.get_program_offers = mock.Mock()

        with LogCapture(LOGGER_NAME) as l:
            self.assert_correct_offers(site_offers)
            l.check((
                LOGGER_NAME,
                'WARNING',
                'CustomApplicator processed Basket [{}] from Request [{}] and User [{}] without a bundle.'
                .format(self.basket, None, self.user),
            ))

        self.assertFalse(self.applicator.get_program_offers.called
                         )  # Verify there was no attempt to match off a bundle
示例#6
0
    def test_log_is_fired_when_get_offers_without_bundle(self):
        """ Verify that logs are fired when no bundle id is given but offers are being applied"""
        existing_offers = list(
            ConditionalOffer.active.filter(offer_type=ConditionalOffer.SITE))
        site_offers = ConditionalOfferFactory.create_batch(3) + existing_offers

        self.applicator._get_program_offers = mock.Mock()  # pylint: disable=protected-access

        with LogCapture(LOGGER_NAME) as logger:
            self.assert_correct_offers(site_offers)
            logger.check((
                LOGGER_NAME,
                'WARNING',
                'CustomApplicator processed Basket [{}] from Request [{}] and User [{}] without a bundle.'
                .format(self.basket, None, self.user),
            ))
        # Verify there was no attempt to match off a bundle
        self.assertFalse(self.applicator._get_program_offers.called)  # pylint: disable=protected-access