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

wrapper_tests.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import datetime
  2. from django.test import TestCase
  3. from mock import patch
  4. from oscar.apps.partner.wrappers import DefaultWrapper
  5. from oscar.apps.partner.models import StockRecord
  6. from oscar.test.helpers import create_product
  7. class DefaultWrapperTests(TestCase):
  8. def setUp(self):
  9. self.wrapper = DefaultWrapper()
  10. self.product = create_product()
  11. def test_num_in_stock_is_none_is_available_to_buy(self):
  12. record = StockRecord(num_in_stock=None)
  13. self.assertTrue(self.wrapper.is_available_to_buy(record))
  14. def test_zero_stock_is_not_available_to_buy(self):
  15. record = StockRecord(num_in_stock=0)
  16. self.assertFalse(self.wrapper.is_available_to_buy(record))
  17. def test_nonzero_stock_is_available_to_buy(self):
  18. record = StockRecord(num_in_stock=10)
  19. self.assertTrue(self.wrapper.is_available_to_buy(record))
  20. def test_matching_purchase_is_permitted(self):
  21. record = StockRecord(num_in_stock=4, product=self.product)
  22. result, reason = self.wrapper.is_purchase_permitted(record, quantity=4)
  23. self.assertTrue(result)
  24. def test_smaller_purchase_is_permitted(self):
  25. record = StockRecord(num_in_stock=4, product=self.product)
  26. result, reason = self.wrapper.is_purchase_permitted(record, quantity=3)
  27. self.assertTrue(result)
  28. def test_too_large_purchase_is_not_permitted(self):
  29. record = StockRecord(num_in_stock=4, product=self.product)
  30. result, reason = self.wrapper.is_purchase_permitted(record, quantity=5)
  31. self.assertFalse(result)
  32. def test_max_purchase_quantity(self):
  33. record = StockRecord(num_in_stock=4, product=self.product)
  34. self.assertEqual(record.num_in_stock, self.wrapper.max_purchase_quantity(record))
  35. def test_availability_code_for_in_stock(self):
  36. record = StockRecord(num_in_stock=4, product=self.product)
  37. self.assertEqual('instock', self.wrapper.availability_code(record))
  38. def test_availability_code_for_zero_stock(self):
  39. record = StockRecord(num_in_stock=0, product=self.product)
  40. self.assertEqual('outofstock', self.wrapper.availability_code(record))
  41. def test_availability_code_for_null_stock_but_available(self):
  42. record = StockRecord(num_in_stock=None, product=self.product)
  43. self.assertEqual('available', self.wrapper.availability_code(record))
  44. def test_availability_message_for_in_stock(self):
  45. record = StockRecord(num_in_stock=4, product=self.product)
  46. self.assertEqual(u'In stock (4 available)', unicode(self.wrapper.availability(record)))
  47. def test_availability_message_for_available(self):
  48. record = StockRecord(num_in_stock=None, product=self.product)
  49. self.assertEqual(u'Available', unicode(self.wrapper.availability(record)))
  50. def test_availability_message_for_out_of_stock(self):
  51. record = StockRecord(num_in_stock=0, product=self.product)
  52. self.assertEqual(u'Not available', unicode(self.wrapper.availability(record)))
  53. def test_backorder_purchase_is_permitted(self):
  54. record = StockRecord(num_in_stock=None, product=self.product)
  55. with patch.object(self.wrapper, 'max_purchase_quantity') as m:
  56. m.return_value = None
  57. result, reason = self.wrapper.is_purchase_permitted(record)
  58. self.assertTrue(result)
  59. def test_dispatch_date_for_in_stock(self):
  60. tomorrow = datetime.date.today() + datetime.timedelta(days=1)
  61. record = StockRecord(product=self.product, num_in_stock=4)
  62. self.assertEquals(tomorrow, self.wrapper.dispatch_date(record))
  63. def test_dispatch_date_for_out_of_stock(self):
  64. date = datetime.date.today() + datetime.timedelta(days=7)
  65. record = StockRecord(product=self.product)
  66. self.assertEquals(date, self.wrapper.dispatch_date(record))