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.

model_tests.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from decimal import Decimal as D
  2. from django.test import TestCase
  3. from oscar.test.helpers import create_product
  4. from oscar.apps.partner.abstract_models import partner_wrappers
  5. class DummyWrapper(object):
  6. def availability(self, stockrecord):
  7. return 'Dummy response'
  8. def dispatch_date(self, stockrecord):
  9. return "Another dummy response"
  10. class TestStockRecord(TestCase):
  11. def setUp(self):
  12. self.product = create_product(price=D('10.00'), num_in_stock=10)
  13. self.stockrecord = self.product.stockrecord
  14. def test_get_price_incl_tax_defaults_to_no_tax(self):
  15. self.assertEquals(D('10.00'), self.product.stockrecord.price_incl_tax)
  16. def test_get_price_excl_tax_returns_correct_value(self):
  17. self.assertEquals(D('10.00'), self.product.stockrecord.price_excl_tax)
  18. def test_net_stock_level_with_no_allocation(self):
  19. self.assertEquals(10, self.product.stockrecord.net_stock_level)
  20. def test_net_stock_level_with_allocation(self):
  21. self.product.stockrecord.allocate(5)
  22. self.assertEquals(10-5, self.product.stockrecord.net_stock_level)
  23. def test_allocated_does_not_alter_num_in_stock(self):
  24. self.stockrecord.allocate(5)
  25. self.assertEqual(10, self.stockrecord.num_in_stock)
  26. self.assertEqual(5, self.stockrecord.num_allocated)
  27. def test_allocation_handles_null_value(self):
  28. self.stockrecord.num_allocated = None
  29. self.stockrecord.allocate(5)
  30. def test_consuming_allocation(self):
  31. self.stockrecord.allocate(5)
  32. self.stockrecord.consume_allocation(3)
  33. self.assertEqual(2, self.stockrecord.num_allocated)
  34. self.assertEqual(7, self.stockrecord.num_in_stock)
  35. def test_cancelling_allocation(self):
  36. self.stockrecord.allocate(5)
  37. self.stockrecord.cancel_allocation(4)
  38. self.assertEqual(1, self.stockrecord.num_allocated)
  39. self.assertEqual(10, self.stockrecord.num_in_stock)
  40. def test_cancelling_allocation_ignores_too_big_allocations(self):
  41. self.stockrecord.allocate(5)
  42. self.stockrecord.cancel_allocation(6)
  43. self.assertEqual(0, self.stockrecord.num_allocated)
  44. self.assertEqual(10, self.stockrecord.num_in_stock)
  45. def test_max_purchase_quantity(self):
  46. self.assertEqual(10, self.stockrecord.max_purchase_quantity())
  47. class CustomWrapperTests(TestCase):
  48. def setUp(self):
  49. partner_wrappers['Acme'] = DummyWrapper()
  50. def tearDown(self):
  51. del partner_wrappers['Acme']
  52. def test_wrapper_availability_gets_called(self):
  53. product = create_product(price=D('10.00'), partner="Acme", num_in_stock=10)
  54. self.assertEquals(u"Dummy response", unicode(product.stockrecord.availability))
  55. def test_wrapper_dispatch_date_gets_called(self):
  56. product = create_product(price=D('10.00'), partner="Acme", num_in_stock=10)
  57. self.assertEquals("Another dummy response", product.stockrecord.dispatch_date)