Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: TT-206 return 404 when a time entry is not running
  • Loading branch information
eduardisrael committed Apr 9, 2021
commit 3d1e25921e2b8f0d26336b7ae6443ffdec9d7e8e
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def test_get_running_should_call_find_running(
repository_update_mock.assert_called_once_with(tenant_id, owner_id)


def test_get_running_should_return_not_found_if_StopIteration(
def test_get_running_should_return_no_content_if_StopIteration(
client: FlaskClient,
mocker: MockFixture,
valid_header: dict,
Expand All @@ -610,7 +610,7 @@ def test_get_running_should_return_not_found_if_StopIteration(
"/time-entries/running", headers=valid_header, follow_redirects=True
)

assert HTTPStatus.NOT_FOUND == response.status_code
assert HTTPStatus.NO_CONTENT == response.status_code
repository_update_mock.assert_called_once_with(tenant_id, owner_id)


Expand Down
8 changes: 8 additions & 0 deletions time_tracker_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
CosmosResourceExistsError,
CosmosResourceNotFoundError,
CosmosHttpResponseError,
CosmosClientTimeoutError,
)
from faker import Faker
from flask import current_app as app, Flask
Expand Down Expand Up @@ -141,6 +142,13 @@ def handle_not_found_errors(error):
return {'message': 'It was not found'}, HTTPStatus.NOT_FOUND


@api.errorhandler(CosmosClientTimeoutError)
@api.errorhandler(StopIteration)
def handle_not_found_errors(error):
app.logger.error(error)
return {'message': 'No Content'}, HTTPStatus.NO_CONTENT


@api.errorhandler(CosmosHttpResponseError)
def handle_cosmos_http_response_error(error):
app.logger.error(error)
Expand Down
2 changes: 1 addition & 1 deletion time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def post(self, id):

@ns.route('/running')
@ns.response(HTTPStatus.OK, 'The time entry that is active: currently running')
@ns.response(HTTPStatus.NOT_FOUND, 'There is no time entry running right now')
@ns.response(HTTPStatus.NO_CONTENT, 'There is no time entry running right now')
class ActiveTimeEntry(Resource):
@ns.doc('running_time_entry')
@ns.marshal_with(time_entry)
Expand Down
5 changes: 4 additions & 1 deletion time_tracker_api/time_entries/time_entries_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ def find_running(
)

function_mapper = self.get_mapper_or_dict(mapper)
return function_mapper(next(result))
try:
return function_mapper(next(result))
except StopIteration as no_result:
raise CustomError(HTTPStatus.NO_CONTENT)

def validate_data(self, data, event_context: EventContext):
start_date = data.get('start_date')
Expand Down