3737fake_time_entry .update (valid_time_entry_input )
3838
3939
40- def test_create_time_entry_with_invalid_date_range_should_raise_bad_request_error (
40+ def test_create_time_entry_with_invalid_date_range_should_raise_bad_request (
4141 client : FlaskClient , mocker : MockFixture , valid_header : dict
4242):
4343 from time_tracker_api .time_entries .time_entries_namespace import (
@@ -63,7 +63,7 @@ def test_create_time_entry_with_invalid_date_range_should_raise_bad_request_erro
6363 repository_container_create_item_mock .assert_not_called ()
6464
6565
66- def test_create_time_entry_with_end_date_in_future_should_raise_bad_request_error (
66+ def test_create_time_entry_with_end_date_in_future_should_raise_bad_request (
6767 client : FlaskClient , mocker : MockFixture , valid_header : dict
6868):
6969 from time_tracker_api .time_entries .time_entries_namespace import (
@@ -180,30 +180,35 @@ def test_get_time_entry_should_succeed_with_valid_id(
180180 dao_get_mock .assert_called_once_with (str (valid_id ))
181181
182182
183- def test_get_time_entry_should_response_with_unprocessable_entity_for_invalid_id_format (
184- client : FlaskClient , mocker : MockFixture , valid_header : dict
183+ @pytest .mark .parametrize (
184+ 'http_exception,http_status' ,
185+ [
186+ (NotFound , HTTPStatus .NOT_FOUND ),
187+ (UnprocessableEntity , HTTPStatus .UNPROCESSABLE_ENTITY ),
188+ ],
189+ )
190+ def test_get_time_entry_raise_http_exception (
191+ client : FlaskClient ,
192+ mocker : MockFixture ,
193+ valid_header : dict ,
194+ valid_id : str ,
195+ http_exception : HTTPException ,
196+ http_status : tuple ,
185197):
186198 from time_tracker_api .time_entries .time_entries_namespace import (
187199 time_entries_dao ,
188200 )
189- from werkzeug .exceptions import UnprocessableEntity
190-
191- invalid_id = fake .word ()
192201
193- repository_find_mock = mocker .patch .object (
194- time_entries_dao .repository , 'find' , side_effect = UnprocessableEntity
195- )
202+ time_entries_dao .repository .find = Mock (side_effect = http_exception )
196203
197204 response = client .get (
198- "/time-entries/%s" % invalid_id ,
205+ f "/time-entries/{ valid_id } " ,
199206 headers = valid_header ,
200207 follow_redirects = True ,
201208 )
202209
203- assert HTTPStatus .UNPROCESSABLE_ENTITY == response .status_code
204- repository_find_mock .assert_called_once_with (
205- str (invalid_id ), ANY ,
206- )
210+ assert http_status == response .status_code
211+ time_entries_dao .repository .find .assert_called_once_with (valid_id , ANY )
207212
208213
209214def test_update_time_entry_calls_partial_update_with_incoming_payload (
@@ -243,7 +248,7 @@ def test_update_time_entry_should_reject_bad_request(
243248
244249 invalid_time_entry_data = valid_time_entry_input .copy ()
245250 invalid_time_entry_data .update (
246- {"project_id" : fake .pyint (min_value = 1 , max_value = 100 ), }
251+ {"project_id" : fake .pyint (min_value = 1 , max_value = 100 )}
247252 )
248253 repository_update_mock = mocker .patch .object (
249254 time_entries_dao .repository , 'update' , return_value = fake_time_entry
@@ -487,7 +492,7 @@ def test_get_running_should_call_find_running(
487492 repository_update_mock .assert_called_once_with (tenant_id , owner_id )
488493
489494
490- def test_get_running_should_return_not_found_if_find_running_throws_StopIteration (
495+ def test_get_running_should_return_not_found_if_StopIteration (
491496 client : FlaskClient ,
492497 mocker : MockFixture ,
493498 valid_header : dict ,
0 commit comments