11import pytest
22import json
3+ from faker import Faker
34
45import azure .functions as func
56
@@ -25,7 +26,7 @@ def test__time_entry_azure_endpoint__creates_an_time_entry__when_time_entry_has_
2526 test_db , time_entry_factory , activity_factory , insert_activity
2627):
2728 inserted_activity = insert_activity (activity_factory (), test_db )
28- time_entry_body = time_entry_factory (activity_id = inserted_activity .id , technologies = "[jira,sql]" ).__dict__
29+ time_entry_body = time_entry_factory (activity_id = inserted_activity .id ).__dict__
2930
3031 body = json .dumps (time_entry_body ).encode ("utf-8" )
3132 req = func .HttpRequest (
@@ -46,7 +47,7 @@ def test__delete_time_entries_azure_endpoint__returns_an_time_entry_with_true_de
4647 test_db , time_entry_factory , insert_time_entry , insert_activity , activity_factory ,
4748):
4849 inserted_activity = insert_activity (activity_factory (), test_db ).__dict__
49- time_entry_body = time_entry_factory (activity_id = inserted_activity ["id" ], technologies = "[jira,sql]" )
50+ time_entry_body = time_entry_factory (activity_id = inserted_activity ["id" ])
5051 inserted_time_entry = insert_time_entry (time_entry_body , test_db )
5152
5253 req = func .HttpRequest (
@@ -76,3 +77,75 @@ def test__delete_time_entries_azure_endpoint__returns_a_status_code_400__when_ti
7677
7778 assert response .status_code == 400
7879 assert response .get_body () == b'Invalid Format ID'
80+
81+
82+ def test__update_time_entry_azure_endpoint__returns_an_time_entry__when_found_an_time_entry_to_update (
83+ test_db , time_entry_factory , insert_time_entry , activity_factory , insert_activity
84+ ):
85+ inserted_activity = insert_activity (activity_factory (), test_db )
86+ existent_time_entries = time_entry_factory (activity_id = inserted_activity .id )
87+ inserted_time_entries = insert_time_entry (existent_time_entries , test_db ).__dict__
88+
89+ time_entry_body = {"description" : Faker ().sentence ()}
90+
91+ req = func .HttpRequest (
92+ method = 'PUT' ,
93+ body = json .dumps (time_entry_body ).encode ("utf-8" ),
94+ url = TIME_ENTRY_URL ,
95+ route_params = {"id" : inserted_time_entries ["id" ]},
96+ )
97+
98+ response = azure_time_entries ._update_time_entry .update_time_entry (req )
99+ activitiy_json_data = response .get_body ().decode ("utf-8" )
100+ inserted_time_entries .update (time_entry_body )
101+
102+ assert response .status_code == 200
103+ assert activitiy_json_data == json .dumps (inserted_time_entries )
104+
105+
106+ def test__update_time_entries_azure_endpoint__returns_a_status_code_400__when_time_entry_recive_invalid_format_id ():
107+ time_entry_body = {"description" : Faker ().sentence ()}
108+
109+ req = func .HttpRequest (
110+ method = "PUT" ,
111+ body = json .dumps (time_entry_body ).encode ("utf-8" ),
112+ url = TIME_ENTRY_URL ,
113+ route_params = {"id" : Faker ().sentence ()},
114+ )
115+
116+ response = azure_time_entries ._update_time_entry .update_time_entry (req )
117+
118+ assert response .status_code == 400
119+ assert response .get_body () == b'Invalid Format ID'
120+
121+
122+ def test__update_time_entries_azure_endpoint__returns_a_status_code_404__when_not_found_an_time_entry_to_update ():
123+ time_entry_body = {"description" : Faker ().sentence ()}
124+
125+ req = func .HttpRequest (
126+ method = "PUT" ,
127+ body = json .dumps (time_entry_body ).encode ("utf-8" ),
128+ url = TIME_ENTRY_URL ,
129+ route_params = {"id" : Faker ().pyint ()},
130+ )
131+
132+ response = azure_time_entries ._update_time_entry .update_time_entry (req )
133+
134+ assert response .status_code == 404
135+ assert response .get_body () == b'Not found'
136+
137+
138+ def test__update_time_entries_azure_endpoint__returns_a_status_code_400__when_time_entry_recive_invalid_body ():
139+
140+ time_entry_body = Faker ().pydict (5 , True , str )
141+ req = func .HttpRequest (
142+ method = "PUT" ,
143+ body = json .dumps (time_entry_body ).encode ("utf-8" ),
144+ url = TIME_ENTRY_URL ,
145+ route_params = {"id" : Faker ().pyint ()},
146+ )
147+
148+ response = azure_time_entries ._update_time_entry .update_time_entry (req )
149+
150+ assert response .status_code == 400
151+ assert response .get_body () == b'Incorrect time entry body'
0 commit comments