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.

fixed_price_benefit_tests.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 import models
  5. from oscar.apps.basket.models import Basket
  6. from oscar.test.helpers import create_product
  7. class TestAFixedPriceDiscountAppliedWithCountCondition(TestCase):
  8. def setUp(self):
  9. range = models.Range.objects.create(
  10. name="All products", includes_all_products=True)
  11. self.condition = models.CountCondition.objects.create(
  12. range=range,
  13. type=models.Condition.COUNT,
  14. value=3)
  15. self.benefit = models.FixedPriceBenefit.objects.create(
  16. range=range,
  17. type=models.Benefit.FIXED_PRICE,
  18. value=D('20.00'))
  19. self.basket = G(Basket)
  20. def test_applies_correctly_to_empty_basket(self):
  21. discount = self.benefit.apply(self.basket, self.condition)
  22. self.assertEqual(D('0.00'), discount)
  23. self.assertEqual(0, self.basket.num_items_with_discount)
  24. self.assertEqual(0, self.basket.num_items_without_discount)
  25. def test_applies_correctly_to_basket_which_is_worth_less_than_value(self):
  26. for product in [create_product(price=D('6.00'))]:
  27. self.basket.add_product(product, 3)
  28. discount = self.benefit.apply(self.basket, self.condition)
  29. self.assertEqual(D('0.00'), discount)
  30. self.assertEqual(0, self.basket.num_items_with_discount)
  31. self.assertEqual(3, self.basket.num_items_without_discount)
  32. def test_applies_correctly_to_basket_which_is_worth_the_same_as_value(self):
  33. for product in [create_product(price=D('5.00'))]:
  34. self.basket.add_product(product, 4)
  35. discount = self.benefit.apply(self.basket, self.condition)
  36. self.assertEqual(D('0.00'), discount)
  37. self.assertEqual(0, self.basket.num_items_with_discount)
  38. self.assertEqual(4, self.basket.num_items_without_discount)
  39. def test_applies_correctly_to_basket_which_is_more_than_value(self):
  40. for product in [create_product(price=D('8.00'))]:
  41. self.basket.add_product(product, 4)
  42. discount = self.benefit.apply(self.basket, self.condition)
  43. self.assertEqual(D('4.00'), discount)
  44. self.assertEqual(3, self.basket.num_items_with_discount)
  45. self.assertEqual(1, self.basket.num_items_without_discount)