-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
113 lines (99 loc) · 2.82 KB
/
test_api.py
File metadata and controls
113 lines (99 loc) · 2.82 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from fastapi.testclient import TestClient
from app import app
from enums import Stacks
client = TestClient(app)
def test_standard_package():
response = client.post("/sort",
json=
{
"width": 100,
"height": 100,
"length": 100,
"mass": 10
})
assert response.status_code == 200
assert response.text == Stacks.STANDARD.value
def test_bulky_package_volume():
package = {
"width": 100,
"height": 100,
"length": 100.1, # Just over 1,000,000 cm³
"mass": 10
}
response = client.post("/sort", json=package)
assert response.status_code == 200
assert response.text == Stacks.SPECIAL.value
def test_bulky_package_dimension():
package = {
"width": 151, # Over 150cm
"height": 100,
"length": 100,
"mass": 10
}
response = client.post("/sort", json=package)
assert response.status_code == 200
assert response.text == Stacks.SPECIAL.value
def test_heavy_package():
package = {
"width": 100,
"height": 100,
"length": 100,
"mass": 21 # Over 20kg
}
response = client.post("/sort", json=package)
assert response.status_code == 200
assert response.text == Stacks.SPECIAL.value
def test_rejected_package():
package = {
"width": 101,
"height": 100,
"length": 100,
"mass": 21
}
response = client.post("/sort", json=package)
assert response.status_code == 200
assert response.text == Stacks.REJECTED.value
def test_invalid_package_negative_values():
package = {
"width": -1,
"height": 100,
"length": 100,
"mass": 10
}
response = client.post("/sort", json=package)
assert response.status_code == 422 # Validation error
def test_invalid_package_negative_mass_values():
package = {
"width": 10,
"height": 100,
"length": 100,
"mass": -10
}
response = client.post("/sort", json=package)
assert response.status_code == 422 # Validation error
def test_invalid_package_missing_values():
package = {
"width": 100,
"height": 100
# missing length and mass
}
response = client.post("/sort", json=package)
assert response.status_code == 422 # Validation error
def test_invalid_package_zero_values():
package = {
"width": 0,
"height": 100,
"length": 100,
"mass": 10
}
response = client.post("/sort", json=package)
assert response.status_code == 422 # Validation error
def test_invalid_package_str_values():
package = {
"width": "abc",
"height": 100,
"length": 100,
"mass": 10
}
response = client.post("/sort", json=package)
assert response.status_code == 422 # Validation error