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
Prev Previous commit
Next Next commit
refactor: TT-201 Add tests for update last entry and update TimeEntri…
…esDao
  • Loading branch information
VanessaIniguezG committed Apr 7, 2021
commit 186a5c09c5a3c12243f700cac9a603592e414d79
65 changes: 65 additions & 0 deletions tests/time_tracker_api/time_entries/time_entries_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,68 @@ def test_get_last_entry(
time_entry = result.pop()
assert isinstance(time_entry, TimeEntryCosmosDBModel)
assert time_entry.__dict__ == expected_item


expected_item = {
'id': 'id',
'owner_id': '1',
'start_date': '2021-03-22T10:00:00.000Z',
'end_date': "2021-03-22T11:00:00.000Z",
'description': 'do some testing',
'tenant_id': 'tenant_id',
'project_id': 'project_id',
'activity_id': 'activity_id',
'technologies': ['python'],

}

running_item = {
'id': 'id',
'owner_id': '1',
'update_last_entry_if_overlap': True,
'start_date': '2021-03-22T10:30:00.000Z',
'end_date': '2021-03-22T11:30:00.000Z',
'description': 'do some testing',
'tenant_id': 'tenant_id',
'project_id': 'project_id',
'activity_id': 'activity_id',
'technologies': ['python'],
}

last_item_update = {
'id': 'id',
'owner_id': '1',
'start_date': '2021-03-22T10:00:00.000Z',
'end_date': "2021-03-22T10:30:00.000Z",
'description': 'do some testing',
'tenant_id': 'tenant_id',
'project_id': 'project_id',
'activity_id': 'activity_id',
'technologies': ['python'],
}

@pytest.mark.parametrize("expected_item, running_item, last_item_update",
[(expected_item, running_item, last_item_update)])
def test_update_last_entry(
event_context: EventContext,
time_entry_repository: TimeEntryCosmosDBRepository,
expected_item,
running_item,
last_item_update
):
query_items_mock = Mock(return_value=[expected_item])
time_entry_repository.container = Mock()
time_entry_repository.container.query_items = query_items_mock

partial_update_mock = Mock(return_value=[last_item_update])
time_entry_repository.partial_update = partial_update_mock

result = time_entry_repository.update_last_entry(running_item, event_context)

partial_update_mock.assert_called_once()
query_items_mock.assert_called_once()
assert result == [last_item_update]




30 changes: 30 additions & 0 deletions tests/time_tracker_api/time_entries/time_entries_namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,33 @@ def test_paginated_sends_max_count_and_offset_on_call_to_repository(
_, kwargs = time_entries_dao.repository.find_all.call_args
assert 'max_count' in kwargs and kwargs['max_count'] is not None
assert 'offset' in kwargs and kwargs['offset'] is not None


def test_update_time_entry_calls_update_last_entry(
client: FlaskClient,
mocker: MockFixture,
valid_header: dict,
valid_id: str,
time_entries_dao,
):
time_entries_dao.repository.partial_update = Mock(return_value={})
time_entries_dao.repository.find = Mock(return_value={})
time_entries_dao.check_whether_current_user_owns_item = Mock()
time_entries_dao.repository.update_last_entry = Mock(return_value={})

update_time_entry = valid_time_entry_input.copy()
update_time_entry['update_last_entry_if_overlap'] = True

response = client.put(
f'/time-entries/{valid_id}',
headers=valid_header,
json=update_time_entry,
follow_redirects=True,
)

assert HTTPStatus.OK == response.status_code
time_entries_dao.repository.partial_update.assert_called_once()
time_entries_dao.repository.find.assert_called_once()
time_entries_dao.check_whether_current_user_owns_item.assert_called_once()
time_entries_dao.repository.update_last_entry.assert_called_once()