-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwarehouse_tests.py
96 lines (73 loc) · 2.59 KB
/
warehouse_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import unittest
from warehouse import Order, OPDept, Customer, InconsistentOrderException, \
Product, Warehouse
class TestOrder(unittest.TestCase):
def test_created_with_created_status(self):
o = Order()
self.assertEqual(o.status, Order.CREATED)
def test_processing_sets_status_to_in_progress(self):
o = Order()
OPDept.process_order(o)
self.assertEqual(o.status, Order.IN_PROGRESS)
def test_client_receive_order_not_yet_sent_throws_error(self):
o = Order()
c = Customer('test name', 'test address')
with self.assertRaises(InconsistentOrderException):
c.receive_order(o)
def test_client_receive_order_sent_sets_status_to_completed(self):
o = Order()
o.status = Order.IN_PROGRESS
c = Customer('test name', 'test address')
c.receive_order(o)
self.assertEqual(o.status, Order.COMPLETED)
class TestCustomer(unittest.TestCase):
def test_creation_sets_name_and_address(self):
c = Customer('test name', 'test address')
self.assertEqual(c.name, 'test name')
self.assertEqual(c.address, 'test address')
class TestOrders(unittest.TestCase):
def test_customer_placing_correct_order_creates_order(self):
p = Product()
w = Warehouse()
w.add_product(p)
c = Customer('test name', 'test address')
initial_length = len(OPDept.orders)
self.assertIsInstance(OPDept.create_order(c, p), Order)
self.assertEqual(initial_length + 1, len(OPDept.orders))
def test_customer_placing_order_inexistent_product_unsuccessful(self):
p = Product()
c = Customer('test name', 'test address')
initial_length = len(OPDept.orders)
self.assertFalse(OPDept.create_order(c, p))
self.assertEqual(initial_length, len(OPDept.orders))
def test_warehouse_report(self):
OPDept.warehouses = []
Warehouse()
w2 = Warehouse()
p = Product()
p2 = Product()
p3 = Product()
w2.products = {
p.number: '3',
p2.number: '1',
p3.number: '5'
}
expected_warehouse_report = {
'zero_stock': 1,
'total_products': 9
}
report = OPDept.report()
self.assertEqual(
report['warehouse_report'],
expected_warehouse_report
)
def test_order_report(self):
pass
class TestProduct(unittest.TestCase):
pass
class TestWarehouse(unittest.TestCase):
pass
def main():
unittest.main()
if __name__ == '__main__':
unittest.main()