def test_save_edit(self):
        """ Previously-created ConditionalOffer, Benefit, and Condition instances should be updated. """
        offer = factories.EnterpriseOfferFactory()
        data = self.generate_data(
            enterprise_customer_uuid=offer.condition.enterprise_customer_uuid,
            benefit_type=Benefit.FIXED)
        self.mock_specific_enterprise_customer_api(
            data['enterprise_customer_uuid'])
        form = EnterpriseOfferForm(request=self.request,
                                   data=data,
                                   instance=offer)
        form.is_valid()
        form.save()

        offer.refresh_from_db()
        self.assert_enterprise_offer_conditions(
            offer,
            data['enterprise_customer_uuid'],
            data['enterprise_customer_name'],
            data['enterprise_customer_catalog_uuid'],
            data['benefit_value'],
            data['benefit_type'],
            'Discount of type {} provided by {} for {}.'.format(
                ConditionalOffer.SITE, data['enterprise_customer_name'][:48],
                data['enterprise_customer_catalog_uuid']),
        )
示例#2
0
 def test_save_offer_name(self):
     """ If a request object is sent, the offer name should include the enterprise name. """
     data = self.generate_data()
     self.mock_specific_enterprise_customer_api(data['enterprise_customer_uuid'])
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer,
         data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'],
         data['benefit_value'],
         data['benefit_type'],
         'Discount of type {} provided by {} for {}.'.format(
             ConditionalOffer.SITE,
             data['enterprise_customer_name'][:48],
             data['enterprise_customer_catalog_uuid']
         ),
         data['contract_discount_type'],
         data['contract_discount_value'],
         data['prepaid_invoice_amount'],
         data['sales_force_id'],
         data['max_global_applications'],
         data['max_discount'],
     )
示例#3
0
 def test_save_create_special_char_title(self):
     """ When the Enterprise's name is international, new objects should still be created."""
     enterprise_customer_uuid = uuid.uuid4()
     data = self.generate_data(
         enterprise_customer_uuid=enterprise_customer_uuid,
         enterprise_customer_name=u'Sp\xe1nish Enterprise',
     )
     self.mock_specific_enterprise_customer_api(data['enterprise_customer_uuid'], name=u'Sp\xe1nish Enterprise')
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer,
         data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'],
         data['benefit_value'],
         data['benefit_type'],
         'Discount of type Site provided by Spánish Enterprise for {}.'.format(
             data['enterprise_customer_catalog_uuid']
         ),
         data['contract_discount_type'],
         data['contract_discount_value'],
         data['prepaid_invoice_amount'],
         data['sales_force_id'],
         data['max_global_applications'],
         data['max_discount'],
     )
示例#4
0
 def test_max_user_discount_clean_with_refunded_enrollments(self):
     """
     Verify that `clean` for `max_user_discount` and `max_user_applications` does not raise error when total consumed
      discount and total max user applications after refund is still less than the value, and the existing offer
      updates with new per user limit and max user application values.
     """
     current_refund_count = 0
     data = self.generate_data(max_user_applications=3,
                               max_user_discount=300)
     self.mock_specific_enterprise_customer_api(
         data['enterprise_customer_uuid'])
     # create an enterprise offer that can provide max $500 discount and consume $400
     offer = factories.EnterpriseOfferFactory(max_user_applications=5,
                                              max_user_discount=500)
     for _ in range(4):
         order = OrderFactory(user=self.user, status=ORDER.COMPLETE)
         OrderDiscountFactory(order=order, offer_id=offer.id, amount=100)
         # create a refund of $200 so the total consumed discount becomes $200
         if current_refund_count < 2:
             RefundFactory(order=order,
                           user=self.user,
                           status=REFUND.COMPLETE)
             current_refund_count += 1
     # now try to update the offer with max_user_discount set to $300
     # which is still greater than the consumed discount after refund $200
     form = EnterpriseOfferForm(request=self.request,
                                data=data,
                                instance=offer)
     self.assertTrue(form.is_valid())
     offer = form.save()
     self.assertEqual(offer.max_user_applications,
                      data['max_user_applications'])
     self.assertEqual(offer.max_user_discount, data['max_user_discount'])
示例#5
0
 def test_save_create(self):
     """
     A new ConditionalOffer, Benefit, Condition, and
     EnterpriseContractMetadata should be created.
     """
     data = self.generate_data()
     self.mock_specific_enterprise_customer_api(
         data['enterprise_customer_uuid'])
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer,
         data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'],
         data['benefit_value'],
         data['benefit_type'],
         'Discount of type {} provided by {} for {}.'.format(
             ConditionalOffer.SITE, data['enterprise_customer_name'][:48],
             data['enterprise_customer_catalog_uuid']),
         data['contract_discount_type'],
         data['contract_discount_value'],
         data['prepaid_invoice_amount'],
     )
示例#6
0
 def test_save_without_commit(self):
     """ No data should be persisted to the database if the commit kwarg is set to False. """
     data = self.generate_data()
     form = EnterpriseOfferForm(request=self.request, data=data)
     self.mock_specific_enterprise_customer_api(data['enterprise_customer_uuid'])
     form.is_valid()
     instance = form.save(commit=False)
     self.assertIsNone(instance.pk)
     self.assertFalse(hasattr(instance, 'benefit'))
     self.assertFalse(hasattr(instance, 'condition'))
示例#7
0
    def test_save_edit(self):
        """ Previously-created ConditionalOffer, Benefit, and Condition instances should be updated. """
        offer = factories.EnterpriseOfferFactory()
        ecm = EnterpriseContractMetadata(
            discount_value=self.contract_discount_value,
            discount_type=self.contract_discount_type,
            amount_paid=self.prepaid_invoice_amount,
        )
        offer.enterprise_contract_metadata = ecm
        data = self.generate_data(
            enterprise_customer_uuid=offer.condition.enterprise_customer_uuid,
            benefit_type=Benefit.FIXED
        )
        self.mock_specific_enterprise_customer_api(data['enterprise_customer_uuid'])
        form = EnterpriseOfferForm(request=self.request, data=data, instance=offer)
        form.is_valid()
        form.save()

        offer.refresh_from_db()
        self.assert_enterprise_offer_conditions(
            offer,
            data['enterprise_customer_uuid'],
            data['enterprise_customer_name'],
            data['enterprise_customer_catalog_uuid'],
            data['benefit_value'],
            data['benefit_type'],
            'Discount of type {} provided by {} for {}.'.format(
                ConditionalOffer.SITE,
                data['enterprise_customer_name'][:48],
                data['enterprise_customer_catalog_uuid']
            ),
            data['contract_discount_type'],
            data['contract_discount_value'],
            data['prepaid_invoice_amount'],
            data['sales_force_id'],
            data['max_global_applications'],
            data['max_discount'],
            data['max_user_applications'],
            data['max_user_discount'],
        )
示例#8
0
 def test_save_create_special_char_title(self):
     """ When the Enterprise's name is international, new objects should still be created."""
     enterprise_customer_uuid = uuid.uuid4()
     data = self.generate_data(
         enterprise_customer_uuid=enterprise_customer_uuid,
         enterprise_customer_name=u'Sp\xe1nish Enterprise',
     )
     self.mock_specific_enterprise_customer_api(
         data['enterprise_customer_uuid'], name=u'Sp\xe1nish Enterprise')
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer, data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'], data['benefit_value'],
         data['benefit_type'], 'Discount provided by Spánish Enterprise.')
示例#9
0
    def test_offer_form_with_per_user_increased_limits(self):
        """
        Verify that an existing enterprise offer can be updated with per user increased limits.
        """
        data = self.generate_data(max_user_applications=40, max_user_discount=7000)
        self.mock_specific_enterprise_customer_api(data['enterprise_customer_uuid'])

        # create an enterprise offer with both max_global_applications and max_discount
        factories.EnterpriseOfferFactory(
            max_user_applications=30,
            max_user_discount=5000
        )
        # now try to update the offer with increased values
        form = EnterpriseOfferForm(request=self.request, data=data)
        self.assertTrue(form.is_valid())
        offer = form.save()
        self.assertEqual(offer.max_user_applications, data['max_user_applications'])
        self.assertEqual(offer.max_user_discount, data['max_user_discount'])
示例#10
0
 def test_save_offer_name(self):
     """ If a request object is sent, the offer name should include the enterprise name. """
     data = self.generate_data()
     self.mock_specific_enterprise_customer_api(
         data['enterprise_customer_uuid'])
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer,
         data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'],
         data['benefit_value'],
         data['benefit_type'],
         'Discount provided by {}.'.format(
             data['enterprise_customer_name']),
     )
示例#11
0
 def test_save_create(self):
     """ A new ConditionalOffer, Benefit, and Condition should be created. """
     data = self.generate_data()
     self.mock_specific_enterprise_customer_api(
         data['enterprise_customer_uuid'])
     form = EnterpriseOfferForm(request=self.request, data=data)
     form.is_valid()
     offer = form.save()
     self.assert_enterprise_offer_conditions(
         offer,
         data['enterprise_customer_uuid'],
         data['enterprise_customer_name'],
         data['enterprise_customer_catalog_uuid'],
         data['benefit_value'],
         data['benefit_type'],
         'Discount provided by {}.'.format(
             data['enterprise_customer_name']),
     )