您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_prices.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from decimal import Decimal as D
  2. from itertools import product
  3. from django.test import TestCase
  4. from oscar.core.prices import Price
  5. class TestPriceObject(TestCase):
  6. def test_can_be_instantiated_with_tax_amount(self):
  7. price = Price("USD", D("10.00"), tax=D("2.00"))
  8. self.assertTrue(price.is_tax_known)
  9. self.assertEqual(D("12.00"), price.incl_tax)
  10. def test_can_have_tax_set_later(self):
  11. price = Price("USD", D("10.00"))
  12. price.tax = D("2.00")
  13. self.assertEqual(D("12.00"), price.incl_tax)
  14. def test_price_equals_reflexivity(self):
  15. for price in (
  16. Price(currency="USD", excl_tax=D("10.00")),
  17. Price(currency="USD", excl_tax=D("10.00"), tax=D("2.00")),
  18. Price(currency="USD", excl_tax=D("10.00"), incl_tax=D("12.00")),
  19. ):
  20. self.assertEqual(price, price)
  21. def test_price_equals_formats(self):
  22. price1 = Price(currency="USD", excl_tax=D("10.00"), tax=D("2.00"))
  23. price2 = Price(currency="USD", excl_tax=D("10.00"), incl_tax=D("12.00"))
  24. self.assertEqual(price1, price2)
  25. def test_price_equals_currency_matters(self):
  26. price1 = Price(currency="EUR", excl_tax=D("10.00"), tax=D("2.00"))
  27. price2 = Price(currency="USD", excl_tax=D("10.00"), tax=D("2.00"))
  28. self.assertNotEqual(price1, price2)
  29. def test_price_equals_transitivity(self):
  30. prices = (
  31. Price(currency="EUR", excl_tax=D("10.00"), tax=D("2.00")),
  32. Price(currency="USD", excl_tax=D("10.00"), tax=D("2.00")),
  33. Price(currency="USD", excl_tax=D("10.00"), incl_tax=D("12.00")),
  34. Price(currency="USD", excl_tax=D("10.00"), tax=D("8.00")),
  35. )
  36. prices_product = product(prices, prices)
  37. for price1, price2 in prices_product:
  38. self.assertEqual(price1 == price2, price2 == price1)