1
1
import uuid
2
2
3
+ from fastapi import status
3
4
from fastapi .testclient import TestClient
4
5
from sqlmodel import Session
5
6
@@ -16,7 +17,7 @@ def test_create_item(
16
17
headers = superuser_token_headers ,
17
18
json = data ,
18
19
)
19
- assert response .status_code == 200
20
+ assert response .status_code == status . HTTP_200_OK
20
21
content = response .json ()
21
22
assert content ["title" ] == data ["title" ]
22
23
assert content ["description" ] == data ["description" ]
@@ -32,7 +33,7 @@ def test_read_item(
32
33
f"{ settings .API_V1_STR } /items/{ item .id } " ,
33
34
headers = superuser_token_headers ,
34
35
)
35
- assert response .status_code == 200
36
+ assert response .status_code == status . HTTP_200_OK
36
37
content = response .json ()
37
38
assert content ["title" ] == item .title
38
39
assert content ["description" ] == item .description
@@ -47,7 +48,7 @@ def test_read_item_not_found(
47
48
f"{ settings .API_V1_STR } /items/{ uuid .uuid4 ()} " ,
48
49
headers = superuser_token_headers ,
49
50
)
50
- assert response .status_code == 404
51
+ assert response .status_code == status . HTTP_404_NOT_FOUND
51
52
content = response .json ()
52
53
assert content ["detail" ] == "Item not found"
53
54
@@ -60,7 +61,7 @@ def test_read_item_not_enough_permissions(
60
61
f"{ settings .API_V1_STR } /items/{ item .id } " ,
61
62
headers = normal_user_token_headers ,
62
63
)
63
- assert response .status_code == 400
64
+ assert response .status_code == status . HTTP_400_BAD_REQUEST
64
65
content = response .json ()
65
66
assert content ["detail" ] == "Not enough permissions"
66
67
@@ -74,7 +75,7 @@ def test_read_items(
74
75
f"{ settings .API_V1_STR } /items/" ,
75
76
headers = superuser_token_headers ,
76
77
)
77
- assert response .status_code == 200
78
+ assert response .status_code == status . HTTP_200_OK
78
79
content = response .json ()
79
80
assert len (content ["data" ]) >= 2
80
81
@@ -89,7 +90,7 @@ def test_update_item(
89
90
headers = superuser_token_headers ,
90
91
json = data ,
91
92
)
92
- assert response .status_code == 200
93
+ assert response .status_code == status . HTTP_200_OK
93
94
content = response .json ()
94
95
assert content ["title" ] == data ["title" ]
95
96
assert content ["description" ] == data ["description" ]
@@ -106,7 +107,7 @@ def test_update_item_not_found(
106
107
headers = superuser_token_headers ,
107
108
json = data ,
108
109
)
109
- assert response .status_code == 404
110
+ assert response .status_code == status . HTTP_404_NOT_FOUND
110
111
content = response .json ()
111
112
assert content ["detail" ] == "Item not found"
112
113
@@ -121,7 +122,7 @@ def test_update_item_not_enough_permissions(
121
122
headers = normal_user_token_headers ,
122
123
json = data ,
123
124
)
124
- assert response .status_code == 400
125
+ assert response .status_code == status . HTTP_400_BAD_REQUEST
125
126
content = response .json ()
126
127
assert content ["detail" ] == "Not enough permissions"
127
128
@@ -134,7 +135,7 @@ def test_delete_item(
134
135
f"{ settings .API_V1_STR } /items/{ item .id } " ,
135
136
headers = superuser_token_headers ,
136
137
)
137
- assert response .status_code == 200
138
+ assert response .status_code == status . HTTP_200_OK
138
139
content = response .json ()
139
140
assert content ["message" ] == "Item deleted successfully"
140
141
@@ -146,7 +147,7 @@ def test_delete_item_not_found(
146
147
f"{ settings .API_V1_STR } /items/{ uuid .uuid4 ()} " ,
147
148
headers = superuser_token_headers ,
148
149
)
149
- assert response .status_code == 404
150
+ assert response .status_code == status . HTTP_404_NOT_FOUND
150
151
content = response .json ()
151
152
assert content ["detail" ] == "Item not found"
152
153
@@ -159,6 +160,6 @@ def test_delete_item_not_enough_permissions(
159
160
f"{ settings .API_V1_STR } /items/{ item .id } " ,
160
161
headers = normal_user_token_headers ,
161
162
)
162
- assert response .status_code == 400
163
+ assert response .status_code == status . HTTP_400_BAD_REQUEST
163
164
content = response .json ()
164
165
assert content ["detail" ] == "Not enough permissions"
0 commit comments