77from time_tracker .projects ._application import _projects as azure_projects
88from time_tracker .projects import _domain as domain
99from time_tracker .projects import _infrastructure as infrastructure
10+ from time_tracker .utils .enums import ResponseEnums as enums
1011
1112PROJECT_URL = '/api/projects/'
1213
@@ -35,7 +36,7 @@ def test__project_azure_endpoint__returns_all_projects(
3536 response = azure_projects ._get_projects .get_projects (req )
3637 projects_json_data = response .get_body ().decode ("utf-8" )
3738
38- assert response .status_code == 200
39+ assert response .status_code == enums . STATUS_OK . value
3940 assert projects_json_data == json .dumps (inserted_projects )
4041
4142
@@ -54,7 +55,7 @@ def test__project_azure_endpoint__returns_an_project__when_project_matches_its_i
5455 response = azure_projects ._get_projects .get_projects (req )
5556 activitiy_json_data = response .get_body ().decode ("utf-8" )
5657
57- assert response .status_code == 200
58+ assert response .status_code == enums . STATUS_OK . value
5859 assert activitiy_json_data == json .dumps (inserted_project )
5960
6061
@@ -69,11 +70,11 @@ def test__projects_azure_endpoint__returns_a_status_code_400__when_project_reciv
6970
7071 response = azure_projects ._get_projects .get_projects (req )
7172
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 ()
7475
7576
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 (
7778 insert_project
7879):
7980 inserted_project = insert_project ().__dict__
@@ -88,7 +89,7 @@ def test__project_azure_endpoint__returns_an_project_with_inactive_status__when_
8889 response = azure_projects ._delete_project .delete_project (req )
8990 project_json_data = json .loads (response .get_body ().decode ("utf-8" ))
9091
91- assert response .status_code == 200
92+ assert response .status_code == enums . STATUS_OK . value
9293 assert project_json_data ['status' ] == 0
9394 assert project_json_data ['deleted' ] is True
9495
@@ -104,11 +105,26 @@ def test__delete_projects_azure_endpoint__returns_a_status_code_400__when_projec
104105
105106 response = azure_projects ._delete_project .delete_project (req )
106107
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 ()
109110
110111
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 (
112128 insert_project
113129):
114130 inserted_project = insert_project ().__dict__
@@ -125,10 +141,44 @@ def test__update_project_azure_endpoint__returns_an_project__when_found_an_proje
125141 activitiy_json_data = response .get_body ().decode ("utf-8" )
126142 inserted_project .update (project_body )
127143
128- assert response .status_code == 200
144+ assert response .status_code == enums . STATUS_OK . value
129145 assert activitiy_json_data == json .dumps (inserted_project )
130146
131147
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+
132182def test__update_projects_azure_endpoint__returns_a_status_code_400__when_project_recive_invalid_id (
133183):
134184 req = func .HttpRequest (
@@ -140,15 +190,15 @@ def test__update_projects_azure_endpoint__returns_a_status_code_400__when_projec
140190
141191 response = azure_projects ._update_project .update_project (req )
142192
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 ()
145195
146196
147197def test__project_azure_endpoint__creates_an_project__when_project_has_all_attributes (
148198 test_db , project_factory , insert_customer , customer_factory
149199):
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__
152202 body = json .dumps (project_body ).encode ("utf-8" )
153203 req = func .HttpRequest (
154204 method = 'POST' ,
@@ -160,5 +210,45 @@ def test__project_azure_endpoint__creates_an_project__when_project_has_all_attri
160210 project_json_data = json .loads (response .get_body ())
161211 project_body ['id' ] = project_json_data ['id' ]
162212
163- assert response .status_code == 201
213+ assert response .status_code == enums . STATUS_CREATED . value
164214 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