Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
 def test_email_status_update_success(self, post_data, response_data,
                                      status_code):
     """ Verify the endpoint updated the email status in offer_assignment """
     enterprise_offer = factories.EnterpriseOfferFactory(
         max_global_applications=None)
     offer_assignment = factories.OfferAssignmentFactory(
         offer=enterprise_offer,
         code='jfhrmndk554lwre',
         user_email='*****@*****.**',
         status=OFFER_ASSIGNED)
     OfferAssignmentEmailAttempt.objects.create(
         offer_assignment=offer_assignment,
         send_id=post_data.get('send_id'))
     with LogCapture(level=logging.INFO) as log:
         with mock.patch(
                 "ecommerce.extensions.api.v2.views.assignmentemail.SailthruClient.receive_hardbounce_post",
                 return_value=True):
             response = self.client.post(self.path,
                                         data=json.dumps(post_data),
                                         content_type='application/json')
     log.check_present()
     self.assertEqual(response.status_code, status_code)
     self.assertDictEqual(response_data, json.loads(response.content))
     updated_offer_assignment = OfferAssignment.objects.get(
         id=offer_assignment.id)
     self.assertEqual(updated_offer_assignment.status,
                      OFFER_ASSIGNMENT_EMAIL_BOUNCED)
Esempio n. 4
0
    def test_slots_available_for_assignment(self, usage, num_orders, max_uses, offer_assignments, expected):
        voucher_data = dict(self.data, usage=usage, num_orders=num_orders)
        voucher = Voucher.objects.create(**voucher_data)

        enterprise_offer = factories.EnterpriseOfferFactory(max_global_applications=max_uses)
        voucher.offers.add(enterprise_offer)

        for assignment_data in offer_assignments:
            factories.OfferAssignmentFactory(offer=enterprise_offer, code=voucher.code, **assignment_data)

        assert voucher.slots_available_for_assignment == expected
Esempio n. 5
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
 def test_email_status_update_success(
         self,
         post_data,
         response_data,
         status_code,
 ):
     """ Verify the endpoint updated the email status in offer_assignment """
     enterprise_offer = factories.EnterpriseOfferFactory(max_global_applications=None)
     offer_assignment = factories.OfferAssignmentFactory(
         offer=enterprise_offer,
         code='jfhrmndk554lwre',
         user_email='*****@*****.**',
     )
     post_data['offer_assignment_id'] = offer_assignment.id
     response_data['offer_assignment_id'] = offer_assignment.id
     response = self.client.post(self.path, data=json.dumps(post_data), content_type='application/json')
     self.assertEqual(response.status_code, status_code)
     self.assertDictEqual(response_data, response.json())
     updated_offer_assignment = OfferAssignment.objects.get(id=offer_assignment.id)
     self.assertEqual(updated_offer_assignment.status, OFFER_ASSIGNED)