-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_nodes.py
106 lines (80 loc) · 3.32 KB
/
test_nodes.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
97
98
99
100
101
102
103
104
105
106
import json
from uuid import UUID
from SBDY_app.patches import serialize_datetime
from SBDY_app.schemas import Import, ImpRequest, ShopUnit, ShopUnitType
from utils import ERROR_400, ERROR_404, Client, client, default, do_test, setup
setup()
def test_unit(client: Client):
id = default(UUID)
data = default(ImpRequest, items=[default(Import, id=id, parentId=None)])
response = client.imports(data.json())
assert response.status_code == 200
model = {**json.loads(data.items[0].json()),
"date": serialize_datetime(data.updateDate), "children": None}
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
def test_empty_category(client: Client):
id = default(UUID)
data = default(ImpRequest, items=[default(
Import, id=id, parentId=None, type=ShopUnitType.CATEGORY, price=None)])
data.items[0].price = None
response = client.imports(data.json())
assert response.status_code == 200
model = {**json.loads(data.items[0].json()),
"date": serialize_datetime(data.updateDate), "children": []}
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
def test_full_category(client: Client):
id = default(UUID)
items = [
default(Import, id=id, parentId=None,
type=ShopUnitType.CATEGORY, price=None),
default(Import, parentId=id,
type=ShopUnitType.OFFER, price=0),
default(Import, parentId=id,
type=ShopUnitType.OFFER, price=0)]
items[0].price = None
data = default(ImpRequest, items=items)
response = client.imports(data.json())
assert response.status_code == 200
date = serialize_datetime(data.updateDate)
model = {**json.loads(items[0].json()), "date": date, "children": [
{**json.loads(items[1].json()), "date": date, "children": None},
{**json.loads(items[2].json()), "date": date, "children": None},
], "price": 0}
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
response = client.nodes(id)
assert response.status_code == 200
ShopUnit(**response.json()) # no ValidationError
assert response.json() == model
def test_nonexisting_items(client: Client):
response = client.nodes(default(UUID))
assert response.status_code == 404
assert response.json() == ERROR_404
response = client.nodes(default(UUID))
assert response.status_code == 404
assert response.json() == ERROR_404
def test_validation(client: Client):
response = client.nodes("abooba")
assert response.status_code == 400
assert response.json() == ERROR_400
response = client.nodes("42069")
assert response.status_code == 400
assert response.json() == ERROR_400
if __name__ == "__main__":
do_test(__file__)