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
16 changes: 12 additions & 4 deletions tests/time_tracker_api/time_entries/time_entries_namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,12 @@ def test_update_time_entry_calls_partial_update_with_incoming_payload(
mocker: MockFixture,
valid_header: dict,
valid_id: str,
owner_id: str,
time_entries_dao,
):
valid_time_entry_input_to_update = valid_time_entry_input.copy()
valid_time_entry_input_to_update["owner_id"] = owner_id

time_entries_dao.repository.partial_update = Mock(return_value={})

time_entries_dao.repository.find = Mock(return_value={})
Expand All @@ -420,13 +424,13 @@ def test_update_time_entry_calls_partial_update_with_incoming_payload(
response = client.put(
f'/time-entries/{valid_id}',
headers=valid_header,
json=valid_time_entry_input,
json=valid_time_entry_input_to_update,
follow_redirects=True,
)

assert HTTPStatus.OK == response.status_code
time_entries_dao.repository.partial_update.assert_called_once_with(
valid_id, valid_time_entry_input, ANY
valid_id, valid_time_entry_input_to_update, ANY
)

time_entries_dao.repository.find.assert_called_once()
Expand Down Expand Up @@ -464,10 +468,14 @@ def test_update_time_entry_raise_not_found(
mocker: MockFixture,
valid_header: dict,
valid_id: str,
owner_id: str,
time_entries_dao,
):
from werkzeug.exceptions import NotFound

valid_time_entry_input_to_update = valid_time_entry_input.copy()
valid_time_entry_input_to_update["owner_id"] = owner_id

time_entries_dao.repository.partial_update = Mock(side_effect=NotFound)

time_entries_dao.repository.find = Mock(return_value={})
Expand All @@ -476,13 +484,13 @@ def test_update_time_entry_raise_not_found(
response = client.put(
f'/time-entries/{valid_id}',
headers=valid_header,
json=valid_time_entry_input,
json=valid_time_entry_input_to_update,
follow_redirects=True,
)

assert HTTPStatus.NOT_FOUND == response.status_code
time_entries_dao.repository.partial_update.assert_called_once_with(
valid_id, valid_time_entry_input, ANY
valid_id, valid_time_entry_input_to_update, ANY
)

time_entries_dao.repository.find.assert_called_once()
Expand Down
1 change: 1 addition & 0 deletions time_tracker_api/time_entries/time_entries_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def create(self, data: dict):

def update(self, id, data: dict, description=None):
event_ctx = self.create_event_context("update", description)
data['owner_id'] = event_ctx.user_id
time_entry = self.repository.find(id, event_ctx)
self.check_whether_current_user_owns_item(time_entry)

Expand Down