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
test: ✅ add unit tests #192
  • Loading branch information
Angeluz-07 committed Jul 21, 2020
commit ce0130332f46ad6fc95df6a6e13e2159776d35f4
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ def time_entry_repository(app: Flask) -> TimeEntryCosmosDBRepository:
return TimeEntryCosmosDBRepository()


@pytest.fixture
def time_entries_dao():
from time_tracker_api.time_entries.time_entries_namespace import (
time_entries_dao,
)

return time_entries_dao


@pytest.yield_fixture(scope="module")
def running_time_entry(
time_entry_repository: TimeEntryCosmosDBRepository,
Expand Down
42 changes: 42 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 @@ -639,3 +639,45 @@ def test_summary_is_called_with_date_range_from_worked_time_module(
repository_find_all_mock.assert_called_once_with(
ANY, conditions=conditions, date_range=date_range
)


def test_paginated_fails_with_no_params(
client: FlaskClient, valid_header: dict,
):
response = client.get('/time-entries/paginated', headers=valid_header)
assert HTTPStatus.BAD_REQUEST == response.status_code


def test_paginated_succeeds_with_valid_params(
client: FlaskClient, valid_header: dict,
):
response = client.get(
'/time-entries/paginated?start=10&length=10', headers=valid_header
)
assert HTTPStatus.OK == response.status_code


def test_paginated_response_contains_expected_props(
client: FlaskClient, valid_header: dict,
):
response = client.get(
'/time-entries/paginated?start=10&length=10', headers=valid_header
)
assert 'data' in json.loads(response.data)
assert 'records_total' in json.loads(response.data)


def test_paginated_sends_max_count_and_offset_on_call_to_repository(
client: FlaskClient, valid_header: dict, time_entries_dao
):
time_entries_dao.repository.find_all = Mock(return_value=[])

response = client.get(
'/time-entries/paginated?start=10&length=10', headers=valid_header
)

time_entries_dao.repository.find_all.assert_called_once()

args, 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