Ejemplo n.º 1
0
    def test_is_satisfied_with_different_users(self, mock_request):
        """
        Ensure that condition returns expected result when wrong user is try to redeem the voucher.

        # code = 'ASD' assigned_to = '*****@*****.**'
        # code = 'ZXC' assigned_to = '*****@*****.**'
        # [email protected] try to redeem `ASD` code
        # `is_satisfied` should return False
        """
        mock_request.return_value = self.request

        voucher1 = factories.VoucherFactory(usage=Voucher.SINGLE_USE,
                                            code='ASD')
        voucher2 = factories.VoucherFactory(usage=Voucher.SINGLE_USE,
                                            code='ZXC')

        enterprise_offers = factories.EnterpriseOfferFactory.create_batch(2)
        voucher1.offers.add(enterprise_offers[0])
        voucher2.offers.add(enterprise_offers[1])

        basket = BasketFactory(site=self.site,
                               owner=UserFactory(email='*****@*****.**'))
        basket.vouchers.add(voucher1)

        factories.OfferAssignmentFactory(offer=enterprise_offers[0],
                                         code=voucher1.code,
                                         user_email='*****@*****.**')
        factories.OfferAssignmentFactory(offer=enterprise_offers[1],
                                         code=voucher2.code,
                                         user_email='*****@*****.**')

        assert self.condition.is_satisfied(enterprise_offers[1],
                                           basket) is False
Ejemplo n.º 2
0
    def test_is_satisfied_when_owner_has_no_assignment(self, mock_request):
        """
        Ensure that condition returns expected result the basket owner has no assignments.

        # voucher has free slots(3) available, no offer assignment for basket owner,
        # assignments(2) exist for other users, voucher has some redemptions(num_orders = 2)
        # basket owner is allowed to redeem the voucher
        """
        mock_request.return_value = self.request
        code = 'TA7WCQD3T4C7GHZ4'
        num_orders = 2
        max_global_applications = 7

        enterprise_offer = factories.EnterpriseOfferFactory(
            max_global_applications=max_global_applications)
        voucher = factories.VoucherFactory(usage=Voucher.MULTI_USE,
                                           code=code,
                                           num_orders=num_orders)
        voucher.offers.add(enterprise_offer)

        factories.OfferAssignmentFactory(offer=enterprise_offer,
                                         code=code,
                                         user_email='*****@*****.**')
        factories.OfferAssignmentFactory(offer=enterprise_offer,
                                         code=code,
                                         user_email='*****@*****.**')

        basket = BasketFactory(site=self.site,
                               owner=UserFactory(email='*****@*****.**'))
        basket.vouchers.add(voucher)

        assert self.condition.is_satisfied(enterprise_offer, basket) is True
Ejemplo n.º 3
0
    def test_is_satisfied_when_no_code_assignments_exists(self, num_orders, redemptions_available):
        """
        Ensure that condition returns expected result when code has no assignments.
        """
        enterprise_offer = factories.EnterpriseOfferFactory()
        voucher = factories.VoucherFactory(usage=Voucher.SINGLE_USE, code='AAA', num_orders=num_orders)
        voucher.offers.add(enterprise_offer)

        basket = factories.BasketFactory(site=self.site, owner=factories.UserFactory(email='*****@*****.**'))
        basket.vouchers.add(voucher)

        assert self.condition.is_satisfied(enterprise_offer, basket) == redemptions_available
Ejemplo n.º 4
0
    def test_is_satisfied(self, num_orders, email, offer_status, condition_result):
        """
        Ensure that condition returns expected result.
        """
        voucher = factories.VoucherFactory(usage=Voucher.SINGLE_USE, num_orders=num_orders)
        enterprise_offer = factories.EnterpriseOfferFactory(max_global_applications=None)
        voucher.offers.add(enterprise_offer)
        basket = factories.BasketFactory(site=self.site, owner=factories.UserFactory(email=email))
        basket.vouchers.add(voucher)
        factories.OfferAssignmentFactory(
            offer=enterprise_offer,
            code=voucher.code,
            user_email=email,
            status=offer_status,
        )

        assert self.condition.is_satisfied(enterprise_offer, basket) == condition_result
Ejemplo n.º 5
0
    def test_multi_use_per_customer_voucher(self):
        """
        Verify `MULTI_USE_PER_CUSTOMER` behaves as expected.
        """
        voucher_data = dict(self.data, usage=Voucher.MULTI_USE_PER_CUSTOMER)
        enterprise_offer = factories.EnterpriseOfferFactory(max_global_applications=3)
        voucher = factories.VoucherFactory(**voucher_data)
        voucher.offers.add(enterprise_offer)

        user1 = UserFactory(email='*****@*****.**')
        user2 = UserFactory(email='*****@*****.**')

        self.use_voucher(voucher, user1)

        is_available, message = voucher.is_available_to_user(user1)
        assert (is_available, message) == (True, '')

        is_available, message = voucher.is_available_to_user(user2)
        assert (is_available, message) == (False, 'This voucher is assigned to another user.')