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

123456789101112131415161718192021222324252627282930313233343536373839
  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.apps.basket.models import Basket
  7. from oscar.test.helpers import create_product
  8. class TestOfferApplicator(TestCase):
  9. def setUp(self):
  10. self.applicator = Applicator()
  11. self.basket = Basket.objects.create()
  12. self.product = create_product(price=D('100'))
  13. rng = G(models.Range, includes_all_products=True)
  14. self.condition = G(models.Condition, range=rng, type="Value",
  15. value=D('100'))
  16. self.benefit = G(models.Benefit, range=rng, type="Absolute",
  17. value=D('10'))
  18. def test_applies_offer_multiple_times_by_default(self):
  19. self.basket.add_product(self.product, 5)
  20. offer = models.ConditionalOffer(
  21. id="test", condition=self.condition, benefit=self.benefit)
  22. discounts = self.applicator.get_basket_discounts(
  23. self.basket, [offer])
  24. self.assertEqual(5, discounts["test"]['freq'])
  25. def test_respects_maximum_applications_field(self):
  26. self.basket.add_product(self.product, 5)
  27. offer = models.ConditionalOffer(
  28. id="test", condition=self.condition, benefit=self.benefit,
  29. max_applications=1)
  30. discounts = self.applicator.get_basket_discounts(
  31. self.basket, [offer])
  32. self.assertEqual(1, discounts["test"]['freq'])