Example #1
0
    def test_get_enterprise_offers(self, enterprise_id, num_expected_offers):
        """ Verify get_enterprise_offers returns correct objects based on filter"""

        uuid = enterprise_id or uuid4()

        for _ in range(2):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=uuid)
            ConditionalOfferFactory(condition=condition)
        for _ in range(3):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=None)
            ConditionalOfferFactory(condition=condition)
        # Make some condition offers with a uuid other than ours
        for _ in range(4):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=uuid4())
            ConditionalOfferFactory(condition=condition)

        with mock.patch(
                'ecommerce.extensions.offer.applicator.get_enterprise_id_for_user'
        ) as mock_ent_id:
            mock_ent_id.return_value = enterprise_id
            enterprise_offers = self.applicator.get_enterprise_offers(
                'some-site', self.user)

        if num_expected_offers == 0:
            assert not enterprise_offers
        else:
            assert enterprise_offers.count() == num_expected_offers
Example #2
0
    def test_get_site_offers(self):
        """ Verify get_site_offers returns correct objects based on filter"""

        uuid = uuid4()
        for _ in range(2):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=uuid)
            ConditionalOfferFactory(condition=condition)
        for _ in range(3):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=None)
            ConditionalOfferFactory(condition=condition)

        assert self.applicator.get_site_offers().count() == 3
Example #3
0
    def test_get_site_offers(self):
        """ Verify get_site_offers returns correct objects based on filter"""
        existing_offers = list(
            ConditionalOffer.active.filter(offer_type=ConditionalOffer.SITE))

        uuid = uuid4()
        for _ in range(2):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=uuid)
            ConditionalOfferFactory(condition=condition)
        for _ in range(3):
            condition = ConditionFactory(program_uuid=None,
                                         enterprise_customer_uuid=None)
            ConditionalOfferFactory(condition=condition)
        assert self.applicator.get_site_offers().count(
        ) == 3 + len(existing_offers)