Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
6 changes: 6 additions & 0 deletions time_tracker_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ def default_error_handler(error):
{'message': 'An unhandled exception occurred.'},
HTTPStatus.INTERNAL_SERVER_ERROR,
)


@api.errorhandler(StopIteration)
def handle_no_content(error):
app.logger.error(error)
return {'message': 'No Content'}, HTTPStatus.NO_CONTENT
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