|
1 | | -def test_post_item(client): |
2 | | - """Check if the item is added to the database""" |
3 | | - response = client.post('/store', json={'name': 'Test Store'}) |
4 | | - store_id = response.json.get('id') |
5 | | - response = client.post( |
6 | | - '/item', |
7 | | - json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id}, |
8 | | - ) |
9 | | - assert response.status_code == 201 |
10 | | - |
11 | | - |
12 | | -def test_get_item(client): |
13 | | - """Check if the response is a dictionary""" |
14 | | - response = client.post('/store', json={'name': 'Test Store'}) |
15 | | - store_id = response.json.get('id') |
16 | | - client.post( |
17 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
18 | | - ) |
19 | | - assert isinstance(client.get('/item/1').json, dict) |
20 | | - |
21 | | - |
22 | | -def test_get_all_items(client): |
23 | | - """CHeck if the response is a list""" |
24 | | - response = client.post('/store', json={'name': 'Test Store'}) |
25 | | - store_id = response.json.get('id') |
26 | | - client.post( |
27 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
28 | | - ) |
29 | | - client.post( |
30 | | - '/item', json={'name': 'Test Item2', 'price': 15.99, 'store_id': store_id} |
31 | | - ) |
32 | | - assert isinstance(client.get('/item').json, list) |
33 | | - |
34 | | - |
35 | | -def test_delete_item(client): |
36 | | - """Check if the item is deleted from the database""" |
37 | | - response = client.post('/store', json={'name': 'Test Store'}) |
38 | | - store_id = response.json.get('id') |
39 | | - client.post( |
40 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
41 | | - ) |
42 | | - response = client.delete('/item/1') |
43 | | - assert response.status_code == 200 |
44 | | - |
45 | | - |
46 | | -def test_put_item(client): |
47 | | - """Check if the item is updated in the database""" |
48 | | - response = client.post('/store', json={'name': 'Test Store'}) |
49 | | - store_id = response.json.get('id') |
50 | | - client.post( |
51 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
52 | | - ) |
53 | | - response = client.put('/item/1', json={'name': 'Test Item', 'price': 15.99}) |
54 | | - assert response.json.get('price') == 15.99 |
55 | | - |
56 | | - |
57 | | -def test_post_store(client): |
58 | | - """Check if the store is added to the database""" |
59 | | - response = client.post('/store', json={'name': 'Test Store'}) |
60 | | - assert response.status_code == 201 |
61 | | - |
62 | | - |
63 | | -def test_get_all_stores(client): |
64 | | - """Check if the response is a dictionary""" |
65 | | - client.post('/store', json={'name': 'Test Store'}) |
66 | | - client.post('/store', json={'name': 'Test Store2'}) |
67 | | - client.post('/store', json={'name': 'Test Store3'}) |
68 | | - assert isinstance(client.get('/store').json, list) |
69 | | - |
70 | | - |
71 | | -def test_delete_store(client): |
72 | | - """Check if the store is deleted from the database""" |
73 | | - response = client.post('/store', json={'name': 'Test Store'}) |
74 | | - store_id = response.json.get('id') |
75 | | - response = client.delete(f'/store/{store_id}') |
76 | | - assert response.status_code == 200 |
77 | | - |
78 | | - |
79 | | -def test_get_tags_from_store(client): |
80 | | - """Check if the response is a list""" |
81 | | - response = client.post('/store', json={'name': 'Test Store'}) |
82 | | - store_id = response.json.get('id') |
83 | | - response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
84 | | - assert isinstance(client.get(f'/store/{store_id}/tag').json, list) |
85 | | - |
86 | | - |
87 | | -def test_post_tags_to_store(client): |
88 | | - """Check if the tag is added to the database""" |
89 | | - response = client.post('/store', json={'name': 'Test Store'}) |
90 | | - store_id = response.json.get('id') |
91 | | - response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
92 | | - assert response.status_code == 201 |
93 | | - |
94 | | - |
95 | | -def test_post_tag_to_item(client): |
96 | | - """Check if the tag is added to the database""" |
97 | | - store_response = client.post('/store', json={'name': 'Test Store'}) |
98 | | - store_id = store_response.json.get('id') |
99 | | - item_response = client.post( |
100 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
101 | | - ) |
102 | | - item_id = item_response.json.get('id') |
103 | | - tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
104 | | - tag_id = tag_response.json.get('id') |
105 | | - response = client.post(f'/item/{item_id}/tag/{tag_id}') |
106 | | - assert response.status_code == 201 |
107 | | - |
108 | | - |
109 | | -def test_delete_tag_from_item(client): |
110 | | - """Check if the tag is deleted from the database""" |
111 | | - store_response = client.post('/store', json={'name': 'Test Store'}) |
112 | | - store_id = store_response.json.get('id') |
113 | | - item_response = client.post( |
114 | | - '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
115 | | - ) |
116 | | - item_id = item_response.json.get('id') |
117 | | - tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
118 | | - tag_id = tag_response.json.get('id') |
119 | | - client.post(f'/item/{item_id}/tag/{tag_id}') |
120 | | - response = client.delete(f'/item/{item_id}/tag/{tag_id}') |
121 | | - assert response.status_code == 200 |
122 | | - |
123 | | - |
124 | | -def test_get_tag(client): |
125 | | - """Check if the tag is added to the database""" |
126 | | - store_response = client.post('/store', json={'name': 'Test Store'}) |
127 | | - store_id = store_response.json.get('id') |
128 | | - tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
129 | | - tag_id = tag_response.json.get('id') |
130 | | - response = client.get(f'/tag/{tag_id}') |
131 | | - assert response.status_code == 200 |
132 | | - |
133 | | - |
134 | | -def test_delete_tag(client): |
135 | | - """Check if the tag is deleted from the database""" |
136 | | - store_response = client.post('/store', json={'name': 'Test Store'}) |
137 | | - store_id = store_response.json.get('id') |
138 | | - tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
139 | | - tag_id = tag_response.json.get('id') |
140 | | - response = client.delete(f'/tag/{tag_id}') |
141 | | - assert response.status_code == 200 |
| 1 | +class TestItems: |
| 2 | + def test_post_item(client): |
| 3 | + """Check if the item is added to the database""" |
| 4 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 5 | + store_id = response.json.get('id') |
| 6 | + response = client.post( |
| 7 | + '/item', |
| 8 | + json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id}, |
| 9 | + ) |
| 10 | + assert response.status_code == 201 |
| 11 | + |
| 12 | + def test_get_item(client): |
| 13 | + """Check if the response is a dictionary""" |
| 14 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 15 | + store_id = response.json.get('id') |
| 16 | + client.post( |
| 17 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 18 | + ) |
| 19 | + assert isinstance(client.get('/item/1').json, dict) |
| 20 | + |
| 21 | + def test_get_all_items(client): |
| 22 | + """CHeck if the response is a list""" |
| 23 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 24 | + store_id = response.json.get('id') |
| 25 | + client.post( |
| 26 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 27 | + ) |
| 28 | + client.post( |
| 29 | + '/item', json={'name': 'Test Item2', 'price': 15.99, 'store_id': store_id} |
| 30 | + ) |
| 31 | + assert isinstance(client.get('/item').json, list) |
| 32 | + |
| 33 | + def test_delete_item(client): |
| 34 | + """Check if the item is deleted from the database""" |
| 35 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 36 | + store_id = response.json.get('id') |
| 37 | + client.post( |
| 38 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 39 | + ) |
| 40 | + response = client.delete('/item/1') |
| 41 | + assert response.status_code == 200 |
| 42 | + |
| 43 | + def test_put_item(client): |
| 44 | + """Check if the item is updated in the database""" |
| 45 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 46 | + store_id = response.json.get('id') |
| 47 | + client.post( |
| 48 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 49 | + ) |
| 50 | + response = client.put('/item/1', json={'name': 'Test Item', 'price': 15.99}) |
| 51 | + assert response.json.get('price') == 15.99 |
| 52 | + |
| 53 | + |
| 54 | +class TestStore: |
| 55 | + def test_post_store(client): |
| 56 | + """Check if the store is added to the database""" |
| 57 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 58 | + assert response.status_code == 201 |
| 59 | + |
| 60 | + def test_get_all_stores(client): |
| 61 | + """Check if the response is a dictionary""" |
| 62 | + client.post('/store', json={'name': 'Test Store'}) |
| 63 | + client.post('/store', json={'name': 'Test Store2'}) |
| 64 | + client.post('/store', json={'name': 'Test Store3'}) |
| 65 | + assert isinstance(client.get('/store').json, list) |
| 66 | + |
| 67 | + def test_delete_store(client): |
| 68 | + """Check if the store is deleted from the database""" |
| 69 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 70 | + store_id = response.json.get('id') |
| 71 | + response = client.delete(f'/store/{store_id}') |
| 72 | + assert response.status_code == 200 |
| 73 | + |
| 74 | + |
| 75 | +class TestTags: |
| 76 | + def test_get_tags_from_store(client): |
| 77 | + """Check if the response is a list""" |
| 78 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 79 | + store_id = response.json.get('id') |
| 80 | + response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 81 | + assert isinstance(client.get(f'/store/{store_id}/tag').json, list) |
| 82 | + |
| 83 | + def test_post_tags_to_store(client): |
| 84 | + """Check if the tag is added to the database""" |
| 85 | + response = client.post('/store', json={'name': 'Test Store'}) |
| 86 | + store_id = response.json.get('id') |
| 87 | + response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 88 | + assert response.status_code == 201 |
| 89 | + |
| 90 | + def test_post_tag_to_item(client): |
| 91 | + """Check if the tag is added to the database""" |
| 92 | + store_response = client.post('/store', json={'name': 'Test Store'}) |
| 93 | + store_id = store_response.json.get('id') |
| 94 | + item_response = client.post( |
| 95 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 96 | + ) |
| 97 | + item_id = item_response.json.get('id') |
| 98 | + tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 99 | + tag_id = tag_response.json.get('id') |
| 100 | + response = client.post(f'/item/{item_id}/tag/{tag_id}') |
| 101 | + assert response.status_code == 201 |
| 102 | + |
| 103 | + def test_delete_tag_from_item(client): |
| 104 | + """Check if the tag is deleted from the database""" |
| 105 | + store_response = client.post('/store', json={'name': 'Test Store'}) |
| 106 | + store_id = store_response.json.get('id') |
| 107 | + item_response = client.post( |
| 108 | + '/item', json={'name': 'Test Item', 'price': 10.99, 'store_id': store_id} |
| 109 | + ) |
| 110 | + item_id = item_response.json.get('id') |
| 111 | + tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 112 | + tag_id = tag_response.json.get('id') |
| 113 | + client.post(f'/item/{item_id}/tag/{tag_id}') |
| 114 | + response = client.delete(f'/item/{item_id}/tag/{tag_id}') |
| 115 | + assert response.status_code == 200 |
| 116 | + |
| 117 | + def test_get_tag(client): |
| 118 | + """Check if the tag is added to the database""" |
| 119 | + store_response = client.post('/store', json={'name': 'Test Store'}) |
| 120 | + store_id = store_response.json.get('id') |
| 121 | + tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 122 | + tag_id = tag_response.json.get('id') |
| 123 | + response = client.get(f'/tag/{tag_id}') |
| 124 | + assert response.status_code == 200 |
| 125 | + |
| 126 | + def test_delete_tag(client): |
| 127 | + """Check if the tag is deleted from the database""" |
| 128 | + store_response = client.post('/store', json={'name': 'Test Store'}) |
| 129 | + store_id = store_response.json.get('id') |
| 130 | + tag_response = client.post(f'/store/{store_id}/tag', json={'name': 'Test Tag'}) |
| 131 | + tag_id = tag_response.json.get('id') |
| 132 | + response = client.delete(f'/tag/{tag_id}') |
| 133 | + assert response.status_code == 200 |
0 commit comments