コード例 #1
0
    def test_get_queryset(self):
        """ Should return only Conditional Offers with Site offer type. """

        # Conditional Offer should contain a condition with enterprise customer uuid set in order to be returned
        partner_conditional_offer = factories.EnterpriseOfferFactory(
            partner=self.partner)

        # Conditional Offer with null Partner or non-matching Partner should not be returned
        null_partner_offer = factories.EnterpriseOfferFactory()
        different_partner_offer = factories.EnterpriseOfferFactory(
            partner=factories.SiteConfigurationFactory().partner)
        enterprise_offers = [
            partner_conditional_offer,
            factories.EnterpriseOfferFactory(
                offer_type=ConditionalOffer.VOUCHER),
            factories.ConditionalOfferFactory(
                offer_type=ConditionalOffer.SITE), null_partner_offer,
            different_partner_offer
        ]

        for offer in enterprise_offers:
            self.mock_specific_enterprise_customer_api(
                offer.condition.enterprise_customer_uuid)

        response = self.client.get(self.path)
        self.assertEqual(list(response.context['object_list']),
                         [partner_conditional_offer])
コード例 #2
0
    def test_get_queryset(self):
        """ Should return only Conditional Offers with Site offer type. """

        # Conditional Offer should contain a condition with program uuid set in order to be returned
        site_conditional_offer = factories.ProgramOfferFactory(
            partner=self.partner)

        # Conditional Offer with null Partner or non-matching Partner should not be returned
        null_partner_offer = factories.ProgramOfferFactory()
        different_partner_offer = factories.ProgramOfferFactory(
            partner=factories.SiteConfigurationFactory().partner)
        program_offers = [
            site_conditional_offer,
            factories.ProgramOfferFactory(offer_type=ConditionalOffer.VOUCHER),
            factories.ConditionalOfferFactory(
                offer_type=ConditionalOffer.SITE), null_partner_offer,
            different_partner_offer
        ]

        for offer in program_offers:
            self.mock_program_detail_endpoint(
                offer.condition.program_uuid,
                self.site_configuration.discovery_api_url)

        response = self.client.get(self.path)
        self.assertEqual(list(response.context['object_list']),
                         [site_conditional_offer])
コード例 #3
0
ファイル: test_models.py プロジェクト: simonclouds/ecommerce
 def test_best_offer(self):
     voucher = Voucher.objects.create(**self.data)
     first_offer = factories.ConditionalOfferFactory()
     voucher.offers.add(first_offer)
     # Test that with the switch off, the offer gets returned.
     Switch.objects.update_or_create(
         name=ENTERPRISE_OFFERS_FOR_COUPONS_SWITCH,
         defaults={'active': False})
     assert voucher.best_offer == first_offer
     # Test that with the switch on, the same offer gets returned.
     Switch.objects.update_or_create(
         name=ENTERPRISE_OFFERS_FOR_COUPONS_SWITCH,
         defaults={'active': True})
     assert voucher.best_offer == first_offer
     # Now add a second enterprise offer, and see that with the switch on, the enterprise offer gets returned.
     second_offer = factories.EnterpriseOfferFactory()
     voucher.offers.add(second_offer)
     assert voucher.best_offer == second_offer
     # Add a third enterprise offer, and see that the first enterprise offer gets returned
     # because of multiple enterprise offers being available.
     third_offer = factories.EnterpriseOfferFactory()
     voucher.offers.add(third_offer)
     assert voucher.best_offer == second_offer
     # Turn the switch off and see that the oldest offer gets returned.
     Switch.objects.update_or_create(
         name=ENTERPRISE_OFFERS_FOR_COUPONS_SWITCH,
         defaults={'active': False})
     assert voucher.best_offer == first_offer
コード例 #4
0
 def test_best_offer(self):
     voucher = Voucher.objects.create(**self.data)
     first_offer = factories.ConditionalOfferFactory()
     voucher.offers.add(first_offer)
     assert voucher.best_offer == first_offer
     # Now add a second enterprise offer, and see that the enterprise offer gets returned.
     second_offer = factories.EnterpriseOfferFactory()
     voucher.offers.add(second_offer)
     assert voucher.best_offer == second_offer
     # Add a third enterprise offer, and see that the first enterprise offer gets returned
     # because of multiple enterprise offers being available.
     third_offer = factories.EnterpriseOfferFactory()
     voucher.offers.add(third_offer)
     assert voucher.best_offer == second_offer
コード例 #5
0
    def test_get_queryset(self):
        """ Should return only Conditional Offers with Site offer type. """

        # Conditional Offer should contain a condition with program uuid set in order to be returned
        site_conditional_offer = factories.ProgramOfferFactory()
        program_offers = [
            site_conditional_offer,
            factories.ProgramOfferFactory(offer_type=ConditionalOffer.VOUCHER),
            factories.ConditionalOfferFactory(offer_type=ConditionalOffer.SITE)
        ]

        for offer in program_offers:
            self.mock_program_detail_endpoint(offer.condition.program_uuid)

        response = self.client.get(self.path)
        self.assertEqual(list(response.context['object_list']), [site_conditional_offer])