7
7
from time_tracker .projects ._application import _projects as azure_projects
8
8
from time_tracker .projects import _domain as domain
9
9
from time_tracker .projects import _infrastructure as infrastructure
10
+ from time_tracker .utils .enums import ResponseEnums as enums
10
11
11
12
PROJECT_URL = '/api/projects/'
12
13
@@ -35,7 +36,7 @@ def test__project_azure_endpoint__returns_all_projects(
35
36
response = azure_projects ._get_projects .get_projects (req )
36
37
projects_json_data = response .get_body ().decode ("utf-8" )
37
38
38
- assert response .status_code == 200
39
+ assert response .status_code == enums . STATUS_OK . value
39
40
assert projects_json_data == json .dumps (inserted_projects )
40
41
41
42
@@ -54,7 +55,7 @@ def test__project_azure_endpoint__returns_an_project__when_project_matches_its_i
54
55
response = azure_projects ._get_projects .get_projects (req )
55
56
activitiy_json_data = response .get_body ().decode ("utf-8" )
56
57
57
- assert response .status_code == 200
58
+ assert response .status_code == enums . STATUS_OK . value
58
59
assert activitiy_json_data == json .dumps (inserted_project )
59
60
60
61
@@ -69,11 +70,11 @@ def test__projects_azure_endpoint__returns_a_status_code_400__when_project_reciv
69
70
70
71
response = azure_projects ._get_projects .get_projects (req )
71
72
72
- assert response .status_code == 400
73
- assert response .get_body () == b'Invalid Format ID'
73
+ assert response .status_code == enums . STATUS_BAD_REQUEST . value
74
+ assert response .get_body () == enums . INVALID_ID . value . encode ()
74
75
75
76
76
- def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_an_project_matching_its_id_is_found (
77
+ def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_a_project_matching_its_id_is_found (
77
78
insert_project
78
79
):
79
80
inserted_project = insert_project ().__dict__
@@ -88,7 +89,7 @@ def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_
88
89
response = azure_projects ._delete_project .delete_project (req )
89
90
project_json_data = json .loads (response .get_body ().decode ("utf-8" ))
90
91
91
- assert response .status_code == 200
92
+ assert response .status_code == enums . STATUS_OK . value
92
93
assert project_json_data ['status' ] == 0
93
94
assert project_json_data ['deleted' ] is True
94
95
@@ -104,11 +105,26 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_projec
104
105
105
106
response = azure_projects ._delete_project .delete_project (req )
106
107
107
- assert response .status_code == 400
108
- assert response .get_body () == b'Invalid Format ID'
108
+ assert response .status_code == enums . STATUS_BAD_REQUEST . value
109
+ assert response .get_body () == enums . INVALID_ID . value . encode ()
109
110
110
111
111
- def test__update_project_azure_endpoint__returns_an_project__when_found_an_project_to_update (
112
+ def test__delete_projects_azure_endpoint__returns_a_status_code_404__when_no_found_a_project_to_delete (
113
+ ):
114
+ req = func .HttpRequest (
115
+ method = "DELETE" ,
116
+ body = None ,
117
+ url = PROJECT_URL ,
118
+ route_params = {"id" : Faker ().pyint ()},
119
+ )
120
+
121
+ response = azure_projects ._delete_project .delete_project (req )
122
+
123
+ assert response .status_code == enums .STATUS_NOT_FOUND .value
124
+ assert response .get_body () == enums .NOT_FOUND .value .encode ()
125
+
126
+
127
+ def test__update_project_azure_endpoint__returns_an_project__when_found_a_project_to_update (
112
128
insert_project
113
129
):
114
130
inserted_project = insert_project ().__dict__
@@ -125,10 +141,44 @@ def test__update_project_azure_endpoint__returns_an_project__when_found_an_proje
125
141
activitiy_json_data = response .get_body ().decode ("utf-8" )
126
142
inserted_project .update (project_body )
127
143
128
- assert response .status_code == 200
144
+ assert response .status_code == enums . STATUS_OK . value
129
145
assert activitiy_json_data == json .dumps (inserted_project )
130
146
131
147
148
+ def test__update_projects_azure_endpoint__returns_a_status_code_404__when_no_found_a_project_to_update (
149
+ project_factory
150
+ ):
151
+ project_body = project_factory ().__dict__
152
+
153
+ req = func .HttpRequest (
154
+ method = "PUT" ,
155
+ body = json .dumps (project_body ).encode ("utf-8" ),
156
+ url = PROJECT_URL ,
157
+ route_params = {"id" : Faker ().pyint ()},
158
+ )
159
+
160
+ response = azure_projects ._update_project .update_project (req )
161
+
162
+ assert response .status_code == enums .STATUS_NOT_FOUND .value
163
+ assert response .get_body () == enums .NOT_FOUND .value .encode ()
164
+
165
+
166
+ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_recive_an_incorrect_body (
167
+ ):
168
+ project_body = Faker ().pydict (5 , True , str )
169
+ req = func .HttpRequest (
170
+ method = "PUT" ,
171
+ body = json .dumps (project_body ).encode ("utf-8" ),
172
+ url = PROJECT_URL ,
173
+ route_params = {"id" : Faker ().pyint ()},
174
+ )
175
+
176
+ response = azure_projects ._update_project .update_project (req )
177
+
178
+ assert response .status_code == enums .STATUS_BAD_REQUEST .value
179
+ assert response .get_body () == enums .INCORRECT_BODY .value .encode ()
180
+
181
+
132
182
def test__update_projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id (
133
183
):
134
184
req = func .HttpRequest (
@@ -140,15 +190,15 @@ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_projec
140
190
141
191
response = azure_projects ._update_project .update_project (req )
142
192
143
- assert response .status_code == 400
144
- assert response .get_body () == b'Invalid Format ID'
193
+ assert response .status_code == enums . STATUS_BAD_REQUEST . value
194
+ assert response .get_body () == enums . INVALID_ID . value . encode ()
145
195
146
196
147
197
def test__project_azure_endpoint__creates_an_project__when_project_has_all_attributes (
148
198
test_db , project_factory , insert_customer , customer_factory
149
199
):
150
- inserted_customer = insert_customer (customer_factory (), test_db )
151
- project_body = project_factory (customer_id = inserted_customer . id ).__dict__
200
+ insert_customer (customer_factory (), test_db )
201
+ project_body = project_factory ().__dict__
152
202
body = json .dumps (project_body ).encode ("utf-8" )
153
203
req = func .HttpRequest (
154
204
method = 'POST' ,
@@ -160,5 +210,45 @@ def test__project_azure_endpoint__creates_an_project__when_project_has_all_attri
160
210
project_json_data = json .loads (response .get_body ())
161
211
project_body ['id' ] = project_json_data ['id' ]
162
212
163
- assert response .status_code == 201
213
+ assert response .status_code == enums . STATUS_CREATED . value
164
214
assert project_json_data == project_body
215
+
216
+
217
+ def test__project_azure_endpoint__returns_a_status_code_400__when_project_does_not_all_attributes (
218
+ test_db , project_factory , insert_customer , customer_factory
219
+ ):
220
+ inserted_customer = insert_customer (customer_factory (), test_db )
221
+ project_body = project_factory (customer_id = inserted_customer .id ).__dict__
222
+ project_body .pop ('name' )
223
+
224
+ body = json .dumps (project_body ).encode ("utf-8" )
225
+ req = func .HttpRequest (
226
+ method = 'POST' ,
227
+ body = body ,
228
+ url = PROJECT_URL ,
229
+ )
230
+
231
+ response = azure_projects ._create_project .create_project (req )
232
+
233
+ assert response .status_code == enums .STATUS_BAD_REQUEST .value
234
+ assert response .get_body () == json .dumps (['The name key is missing in the input data' ]).encode ()
235
+
236
+
237
+ def test__project_azure_endpoint__returns_a_status_code_500__when_project_recive_incorrect_type_data (
238
+ project_factory , insert_customer , customer_factory , test_db
239
+ ):
240
+ insert_customer (customer_factory (), test_db )
241
+ project_body = project_factory (technologies = Faker ().pylist (2 , True , str )).__dict__
242
+
243
+ body = json .dumps (project_body ).encode ("utf-8" )
244
+ print (project_body )
245
+ req = func .HttpRequest (
246
+ method = 'POST' ,
247
+ body = body ,
248
+ url = PROJECT_URL ,
249
+ )
250
+
251
+ response = azure_projects ._create_project .create_project (req )
252
+
253
+ assert response .status_code == enums .INTERNAL_SERVER_ERROR .value
254
+ assert response .get_body () == enums .NOT_CREATED .value .encode ()
0 commit comments