1
1
import json
2
+ from http import HTTPStatus
2
3
3
4
import pytest
4
5
from faker import Faker
7
8
from time_tracker .projects ._application import _projects as azure_projects
8
9
from time_tracker .projects import _domain as domain
9
10
from time_tracker .projects import _infrastructure as infrastructure
10
- from time_tracker .utils .enums import ResponseEnums as enums
11
11
12
12
PROJECT_URL = '/api/projects/'
13
13
@@ -36,7 +36,7 @@ def test__project_azure_endpoint__returns_all_projects(
36
36
response = azure_projects ._get_projects .get_projects (req )
37
37
projects_json_data = response .get_body ().decode ("utf-8" )
38
38
39
- assert response .status_code == enums . STATUS_OK . value
39
+ assert response .status_code == HTTPStatus . OK
40
40
assert projects_json_data == json .dumps (inserted_projects )
41
41
42
42
@@ -55,7 +55,7 @@ def test__project_azure_endpoint__returns_an_project__when_project_matches_its_i
55
55
response = azure_projects ._get_projects .get_projects (req )
56
56
activitiy_json_data = response .get_body ().decode ("utf-8" )
57
57
58
- assert response .status_code == enums . STATUS_OK . value
58
+ assert response .status_code == HTTPStatus . OK
59
59
assert activitiy_json_data == json .dumps (inserted_project )
60
60
61
61
@@ -70,8 +70,8 @@ def test__projects_azure_endpoint__returns_a_status_code_400__when_project_reciv
70
70
71
71
response = azure_projects ._get_projects .get_projects (req )
72
72
73
- assert response .status_code == enums . STATUS_BAD_REQUEST . value
74
- assert response .get_body () == enums . INVALID_ID . value . encode ()
73
+ assert response .status_code == HTTPStatus . BAD_REQUEST
74
+ assert response .get_body () == b"Invalid Format ID"
75
75
76
76
77
77
def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_a_project_matching_its_id_is_found (
@@ -89,7 +89,7 @@ def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_
89
89
response = azure_projects ._delete_project .delete_project (req )
90
90
project_json_data = json .loads (response .get_body ().decode ("utf-8" ))
91
91
92
- assert response .status_code == enums . STATUS_OK . value
92
+ assert response .status_code == HTTPStatus . OK
93
93
assert project_json_data ['status' ] == 0
94
94
assert project_json_data ['deleted' ] is True
95
95
@@ -105,8 +105,8 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_projec
105
105
106
106
response = azure_projects ._delete_project .delete_project (req )
107
107
108
- assert response .status_code == enums . STATUS_BAD_REQUEST . value
109
- assert response .get_body () == enums . INVALID_ID . value . encode ()
108
+ assert response .status_code == HTTPStatus . BAD_REQUEST
109
+ assert response .get_body () == b"Invalid Format ID"
110
110
111
111
112
112
def test__delete_projects_azure_endpoint__returns_a_status_code_404__when_no_found_a_project_to_delete (
@@ -120,8 +120,8 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_404__when_no_fou
120
120
121
121
response = azure_projects ._delete_project .delete_project (req )
122
122
123
- assert response .status_code == enums . STATUS_NOT_FOUND . value
124
- assert response .get_body () == enums . NOT_FOUND . value . encode ()
123
+ assert response .status_code == HTTPStatus . NOT_FOUND
124
+ assert response .get_body () == b"Not found"
125
125
126
126
127
127
def test__update_project_azure_endpoint__returns_an_project__when_found_a_project_to_update (
@@ -141,7 +141,7 @@ def test__update_project_azure_endpoint__returns_an_project__when_found_a_projec
141
141
activitiy_json_data = response .get_body ().decode ("utf-8" )
142
142
inserted_project .update (project_body )
143
143
144
- assert response .status_code == enums . STATUS_OK . value
144
+ assert response .status_code == HTTPStatus . OK
145
145
assert activitiy_json_data == json .dumps (inserted_project )
146
146
147
147
@@ -159,8 +159,8 @@ def test__update_projects_azure_endpoint__returns_a_status_code_404__when_no_fou
159
159
160
160
response = azure_projects ._update_project .update_project (req )
161
161
162
- assert response .status_code == enums . STATUS_NOT_FOUND . value
163
- assert response .get_body () == enums . NOT_FOUND . value . encode ()
162
+ assert response .status_code == HTTPStatus . NOT_FOUND
163
+ assert response .get_body () == b"Not found"
164
164
165
165
166
166
def test__update_projects_azure_endpoint__returns_a_status_code_400__when_recive_an_incorrect_body (
@@ -175,8 +175,8 @@ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_recive
175
175
176
176
response = azure_projects ._update_project .update_project (req )
177
177
178
- assert response .status_code == enums . STATUS_BAD_REQUEST . value
179
- assert response .get_body () == enums . INCORRECT_BODY . value . encode ()
178
+ assert response .status_code == HTTPStatus . BAD_REQUEST
179
+ assert response .get_body () == b"Incorrect body"
180
180
181
181
182
182
def test__update_projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id (
@@ -190,8 +190,8 @@ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_projec
190
190
191
191
response = azure_projects ._update_project .update_project (req )
192
192
193
- assert response .status_code == enums . STATUS_BAD_REQUEST . value
194
- assert response .get_body () == enums . INVALID_ID . value . encode ()
193
+ assert response .status_code == HTTPStatus . BAD_REQUEST
194
+ assert response .get_body () == b"Invalid Format ID"
195
195
196
196
197
197
def test__project_azure_endpoint__creates_an_project__when_project_has_all_attributes (
@@ -210,7 +210,7 @@ def test__project_azure_endpoint__creates_an_project__when_project_has_all_attri
210
210
project_json_data = json .loads (response .get_body ())
211
211
project_body ['id' ] = project_json_data ['id' ]
212
212
213
- assert response .status_code == enums . STATUS_CREATED . value
213
+ assert response .status_code == HTTPStatus . CREATED
214
214
assert project_json_data == project_body
215
215
216
216
@@ -230,7 +230,7 @@ def test__project_azure_endpoint__returns_a_status_code_400__when_project_does_n
230
230
231
231
response = azure_projects ._create_project .create_project (req )
232
232
233
- assert response .status_code == enums . STATUS_BAD_REQUEST . value
233
+ assert response .status_code == HTTPStatus . BAD_REQUEST
234
234
assert response .get_body () == json .dumps (['The name key is missing in the input data' ]).encode ()
235
235
236
236
@@ -250,5 +250,5 @@ def test__project_azure_endpoint__returns_a_status_code_500__when_project_recive
250
250
251
251
response = azure_projects ._create_project .create_project (req )
252
252
253
- assert response .status_code == enums .INTERNAL_SERVER_ERROR . value
254
- assert response .get_body () == enums . NOT_CREATED . value . encode ()
253
+ assert response .status_code == HTTPStatus .INTERNAL_SERVER_ERROR
254
+ assert response .get_body () == b"could not be created"
0 commit comments