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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from decimal import Decimal as D
  2. import datetime
  3. from django.utils import unittest
  4. from oscar.test.helpers import create_product
  5. from oscar.apps.discount.models import DiscountOffer, PERCENTAGE_DISCOUNT, ABSOLUTE_DISCOUNT, FINAL_PRICE
  6. class PercentageDiscountOfferTest(unittest.TestCase):
  7. def setUp(self):
  8. self.offer = DiscountOffer(discount_type=PERCENTAGE_DISCOUNT,
  9. discount_value=D('25.00'))
  10. def test_simple_discounted_price(self):
  11. product = create_product(D('100.00'))
  12. self.assertEquals(D('75.00'), self.offer._get_discount_price(product))
  13. def test_rounded_discounted_price(self):
  14. product = create_product(D('99.99'))
  15. self.assertEquals(D('74.99'), self.offer._get_discount_price(product))
  16. class AbsoluteDiscountOfferTest(unittest.TestCase):
  17. def setUp(self):
  18. self.offer = DiscountOffer(discount_type=ABSOLUTE_DISCOUNT,
  19. discount_value=D('25.00'))
  20. def test_simple_discounted_price(self):
  21. product = create_product(D('100.00'))
  22. self.assertEquals(D('75.00'), self.offer._get_discount_price(product))
  23. def test_discount_larger_than_price_sets_price_to_zero(self):
  24. product = create_product(D('20.00'))
  25. self.assertEquals(D('0.00'), self.offer._get_discount_price(product))
  26. class FixedPriceDiscountOfferTest(unittest.TestCase):
  27. def setUp(self):
  28. self.offer = DiscountOffer(discount_type=FINAL_PRICE,
  29. discount_value=D('25.00'))
  30. def test_simple_discounted_price(self):
  31. product = create_product(D('100.00'))
  32. self.assertEquals(D('25.00'), self.offer._get_discount_price(product))
  33. def test_discounted_price_when_original_is_cheaper(self):
  34. product = create_product(D('20.00'))
  35. self.assertEquals(D('25.00'), self.offer._get_discount_price(product))