Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

wrapper_tests.py 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. from decimal import Decimal as D
  2. from django.test import TestCase
  3. from oscar.apps.partner.wrappers import DefaultWrapper
  4. from oscar.apps.catalogue.models import Product, ProductClass
  5. from oscar.apps.partner.models import StockRecord
  6. class TestStockRecordWithNullStockLevel(TestCase):
  7. """
  8. Stock record with num_in_stock=None
  9. """
  10. def setUp(self):
  11. self.wrapper = DefaultWrapper()
  12. self.product = Product()
  13. self.product.product_class = ProductClass()
  14. self.record = StockRecord(num_in_stock=None, product=self.product)
  15. def test_is_available_to_buy(self):
  16. self.assertTrue(self.wrapper.is_available_to_buy(self.record))
  17. def test_permits_purchase(self):
  18. is_permitted, reason = self.wrapper.is_purchase_permitted(
  19. self.record)
  20. self.assertTrue(is_permitted)
  21. def test_has_no_max_purchase_quantity(self):
  22. self.assertIsNone(self.wrapper.max_purchase_quantity(self.record))
  23. def test_returns_available_code(self):
  24. self.assertEqual(DefaultWrapper.CODE_AVAILABLE,
  25. self.wrapper.availability_code(self.record))
  26. def test_returns_correct_availability_message(self):
  27. self.assertEqual("Available",
  28. self.wrapper.availability(self.record))
  29. def test_returns_no_estimated_dispatch_date(self):
  30. self.assertIsNone(self.wrapper.dispatch_date(self.record))
  31. def test_returns_no_estimated_lead_time(self):
  32. self.assertIsNone(self.wrapper.lead_time(self.record))
  33. def test_returns_zero_tax(self):
  34. self.assertEqual(D('0.00'), self.wrapper.calculate_tax(self.record))
  35. class TestStockRecordOfDigitalProduct(TestCase):
  36. def setUp(self):
  37. self.wrapper = DefaultWrapper()
  38. self.product = Product()
  39. self.product.product_class = ProductClass(track_stock=False)
  40. self.record = StockRecord(num_in_stock=None, product=self.product)
  41. def test_is_available_to_buy(self):
  42. self.assertTrue(self.wrapper.is_available_to_buy(self.record))
  43. def test_permits_purchase(self):
  44. is_permitted, reason = self.wrapper.is_purchase_permitted(
  45. self.record)
  46. self.assertTrue(is_permitted)
  47. def test_has_no_max_purchase_quantity(self):
  48. self.assertIsNone(self.wrapper.max_purchase_quantity(self.record))
  49. def test_returns_available_code(self):
  50. self.assertEqual(DefaultWrapper.CODE_AVAILABLE,
  51. self.wrapper.availability_code(self.record))
  52. def test_returns_correct_availability_message(self):
  53. self.assertEqual("Available",
  54. self.wrapper.availability(self.record))
  55. def test_returns_no_estimated_dispatch_date(self):
  56. self.assertIsNone(self.wrapper.dispatch_date(self.record))
  57. def test_returns_no_estimated_lead_time(self):
  58. self.assertIsNone(self.wrapper.lead_time(self.record))
  59. def test_returns_zero_tax(self):
  60. self.assertEqual(D('0.00'), self.wrapper.calculate_tax(self.record))
  61. class TestStockRecordOfZeroStockProduct(TestCase):
  62. def setUp(self):
  63. self.wrapper = DefaultWrapper()
  64. self.product = Product()
  65. self.product.product_class = ProductClass()
  66. self.record = StockRecord(num_in_stock=0, product=self.product)
  67. def test_is_not_available_to_buy(self):
  68. self.assertFalse(self.wrapper.is_available_to_buy(self.record))
  69. def test_does_not_permit_purchase(self):
  70. is_permitted, reason = self.wrapper.is_purchase_permitted(
  71. self.record)
  72. self.assertFalse(is_permitted)
  73. def test_has_zero_max_purchase_quantity(self):
  74. self.assertEqual(0, self.wrapper.max_purchase_quantity(self.record))
  75. def test_returns_unavailable_code(self):
  76. self.assertEqual(DefaultWrapper.CODE_UNAVAILABLE,
  77. self.wrapper.availability_code(self.record))
  78. def test_returns_correct_availability_message(self):
  79. self.assertEqual("Not available",
  80. self.wrapper.availability(self.record))
  81. def test_returns_no_estimated_dispatch_date(self):
  82. self.assertIsNone(self.wrapper.dispatch_date(self.record))
  83. def test_returns_no_estimated_lead_time(self):
  84. self.assertIsNone(self.wrapper.lead_time(self.record))
  85. def test_returns_zero_tax(self):
  86. self.assertEqual(D('0.00'), self.wrapper.calculate_tax(self.record))
  87. class TestStockRecordWithPositiveStock(TestCase):
  88. def setUp(self):
  89. self.wrapper = DefaultWrapper()
  90. self.product = Product()
  91. self.product.product_class = ProductClass()
  92. self.record = StockRecord(num_in_stock=5, product=self.product)
  93. def test_is_available_to_buy(self):
  94. self.assertTrue(self.wrapper.is_available_to_buy(self.record))
  95. def test_does_permit_purchase_for_smaller_quantities(self):
  96. for x in range(1, 6):
  97. is_permitted, reason = self.wrapper.is_purchase_permitted(
  98. self.record, quantity=x)
  99. self.assertTrue(is_permitted)
  100. def test_does_not_permit_purchase_for_larger_quantities(self):
  101. for x in range(6, 10):
  102. is_permitted, reason = self.wrapper.is_purchase_permitted(
  103. self.record, quantity=x)
  104. self.assertFalse(is_permitted)
  105. def test_has_correct_max_purchase_quantity(self):
  106. self.assertEqual(5, self.wrapper.max_purchase_quantity(self.record))
  107. def test_returns_available_code(self):
  108. self.assertEqual(DefaultWrapper.CODE_IN_STOCK,
  109. self.wrapper.availability_code(self.record))
  110. def test_returns_correct_availability_message(self):
  111. self.assertEqual("In stock (5 available)",
  112. self.wrapper.availability(self.record))
  113. def test_returns_no_estimated_dispatch_date(self):
  114. self.assertIsNone(self.wrapper.dispatch_date(self.record))
  115. def test_returns_no_estimated_lead_time(self):
  116. self.assertIsNone(self.wrapper.lead_time(self.record))
  117. def test_returns_zero_tax(self):
  118. self.assertEqual(D('0.00'), self.wrapper.calculate_tax(self.record))