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

tests.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from decimal import Decimal
  2. from django.test import TestCase
  3. from oscar.address.models import Country
  4. from oscar.basket.models import Basket
  5. from oscar.order.models import ShippingAddress, Order, Batch, BatchLine, ShippingEvent, ShippingEventType, ShippingEventQuantity
  6. class ShippingAddressTest(TestCase):
  7. def test_titleless_salutation_is_stripped(self):
  8. country = Country.objects.get(iso_3166_1_a2='GB')
  9. a = ShippingAddress.objects.create(last_name='Barrington', line1="75 Smith Road", postcode="N4 8TY", country=country)
  10. self.assertEquals("Barrington", a.salutation())
  11. class OrderTest(TestCase):
  12. fixtures = ['sample-order.json']
  13. def setUp(self):
  14. self.order = Order.objects.get(number='100002')
  15. class BatchLineTest(TestCase):
  16. fixtures = ['sample-order.json']
  17. def setUp(self):
  18. self.order = Order.objects.get(number='100002')
  19. self.batch = self.order.batches.get(id=1)
  20. self.line = self.order.lines.get(id=1)
  21. def event(self, type, quantity=None):
  22. """
  23. Creates a shipping event for the test line
  24. """
  25. event = ShippingEvent.objects.create(order=self.order, batch=self.batch, event_type=type)
  26. if quantity == None:
  27. quantity = self.line.quantity
  28. event_quantity = ShippingEventQuantity.objects.create(event=event, line=self.line, quantity=quantity)
  29. def test_shipping_status_is_empty_to_start_with(self):
  30. self.assertEquals('', self.line.shipping_status)
  31. def test_shipping_status_after_full_line_event(self):
  32. type = ShippingEventType.objects.get(code='order_placed')
  33. self.event(type)
  34. self.assertEquals(type.name, self.line.shipping_status)
  35. def test_shipping_status_after_partial_line_event(self):
  36. type = ShippingEventType.objects.get(code='order_placed')
  37. self.event(type, 3)
  38. expected = "%s (%d/%d items)" % (type.name, 3, self.line.quantity)
  39. self.assertEquals(expected, self.line.shipping_status)
  40. def test_has_passed_shipping_status_after_full_line_event(self):
  41. type = ShippingEventType.objects.get(code='order_placed')
  42. self.event(type)
  43. self.assertTrue(self.line.has_shipping_event_occurred(type))
  44. def test_has_passed_shipping_status_after_partial_line_event(self):
  45. type = ShippingEventType.objects.get(code='order_placed')
  46. self.event(type, self.line.quantity - 1)
  47. self.assertFalse(self.line.has_shipping_event_occurred(type))
  48. def test_has_passed_shipping_status_after_multiple_line_event(self):
  49. event_types = [ShippingEventType.objects.get(code='order_placed'),
  50. ShippingEventType.objects.get(code='dispatched')]
  51. for type in event_types:
  52. self.event(type)
  53. for type in event_types:
  54. self.assertTrue(self.line.has_shipping_event_occurred(type))
  55. def test_inconsistent_shipping_status_setting(self):
  56. type = ShippingEventType.objects.get(code='order_placed')
  57. self.event(type, self.line.quantity - 1)
  58. with self.assertRaises(ValueError):
  59. # Quantity is higher for second event than first
  60. type = ShippingEventType.objects.get(code='dispatched')
  61. self.event(type, self.line.quantity)
  62. def test_inconsistent_shipping_quantities(self):
  63. type = ShippingEventType.objects.get(code='order_placed')
  64. self.event(type, self.line.quantity - 1)
  65. with self.assertRaises(ValueError):
  66. # Total quantity is too high
  67. self.event(type, 2)
  68. class ShippingEventQuantityTest(TestCase):
  69. fixtures = ['sample-order.json']
  70. def setUp(self):
  71. self.order = Order.objects.get(number='100002')
  72. self.batch = self.order.batches.get(id=1)
  73. self.line = self.order.lines.get(id=1)
  74. def test_quantity_defaults_to_all(self):
  75. type = ShippingEventType.objects.get(code='order_placed')
  76. event = ShippingEvent.objects.create(order=self.order, batch=self.batch, event_type=type)
  77. event_quantity = ShippingEventQuantity.objects.create(event=event, line=self.line)
  78. self.assertEquals(self.line.quantity, event_quantity.quantity)