You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

applicator_tests.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536
  1. from decimal import Decimal as D
  2. from django.test import TestCase
  3. from django_dynamic_fixture import G
  4. from oscar.apps.offer.utils import Applicator
  5. from oscar.apps.offer import models
  6. from oscar.test.basket import add_product
  7. from oscar.test import factories
  8. class TestOfferApplicator(TestCase):
  9. def setUp(self):
  10. self.applicator = Applicator()
  11. self.basket = factories.create_basket(empty=True)
  12. rng = G(models.Range, includes_all_products=True)
  13. self.condition = G(models.Condition, range=rng, type="Value",
  14. value=D('100'), proxy_class=None)
  15. self.benefit = G(models.Benefit, range=rng, type="Absolute",
  16. value=D('10'))
  17. def test_applies_offer_multiple_times_by_default(self):
  18. add_product(self.basket, D('100'), 5)
  19. offer = models.ConditionalOffer(
  20. id="test", condition=self.condition, benefit=self.benefit)
  21. self.applicator.apply_offers(self.basket, [offer])
  22. self.assertEqual(5, self.basket.offer_applications.applications["test"]['freq'])
  23. def test_respects_maximum_applications_field(self):
  24. add_product(self.basket, D('100'), 5)
  25. offer = models.ConditionalOffer(
  26. id="test", condition=self.condition, benefit=self.benefit,
  27. max_basket_applications=1)
  28. self.applicator.apply_offers(self.basket, [offer])
  29. self.assertEqual(1, self.basket.offer_applications.applications["test"]['freq'])