Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.8 kB
2
Indexable
Never
    def test_get_active_referral_campaigns__country_filter(self):
        retailer = RetailerFactory()
        voucher_template_1 = AdHocVoucherTemplateFactory(retailer_id=retailer.id)
        referee_validation_reward_1 = YoyoReward.objects.create(
            quantity=2, scheme=voucher_template_1
        )
        campaign_1 = ReferralCampaignFactory(
            retailer=retailer,
            referee_validation_reward_id=referee_validation_reward_1.id,
            countries='GB',
        )

        retailer_app_name = 'my_app'
        RetailerApiClientNameFactory(name=retailer_app_name, retailer_id=retailer.id)
        context.api_client_name = retailer_app_name
        context.country = 'GB'

        voucher_template_2 = AdHocVoucherTemplateFactory(retailer_id=retailer.id)
        referee_completion_reward_2 = YoyoReward.objects.create(
            quantity=2, scheme=voucher_template_2
        )
        campaign_2 = ReferralCampaignFactory(
            retailer=retailer,
            referee_completion_reward_id=referee_completion_reward_2.id,
            countries='PL',
        )
        all_referral_campaigns = self.service.get_active_referral_campaigns(all_campaigns=True)
        country_referral_campaigns = self.service.get_active_referral_campaigns()

        all_referral_campaign_1 = all_referral_campaigns[0]
        all_referral_campaign_2 = all_referral_campaigns[1]
        country_referral_campaign_1 = country_referral_campaigns[0]

        self.testcase.assertEqual(len(all_referral_campaigns), 2)
        self.testcase.assertEqual(len(country_referral_campaigns), 1)
        self.testcase.assertEqual(all_referral_campaign_1, campaign_1)
        self.testcase.assertEqual(all_referral_campaign_2, campaign_2)
        self.testcase.assertEqual(country_referral_campaign_1, campaign_1)