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
25 changes: 9 additions & 16 deletions tests/time_tracker_api/time_entries/time_entries_namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def test_list_all_time_entries(
time_entries_dao,
)

repository_find_all_mock = mocker.patch.object(
time_entries_dao.repository, 'find_all', return_value=[]
dao_get_all_mock = mocker.patch.object(
time_entries_dao, 'get_all', return_value=[]
)

response = client.get(
Expand All @@ -156,7 +156,7 @@ def test_list_all_time_entries(

assert HTTPStatus.OK == response.status_code
assert [] == json.loads(response.data)
repository_find_all_mock.assert_called_once()
dao_get_all_mock.assert_called_once()


def test_get_time_entry_should_succeed_with_valid_id(
Expand All @@ -166,8 +166,8 @@ def test_get_time_entry_should_succeed_with_valid_id(
time_entries_dao,
)

repository_find_mock = mocker.patch.object(
time_entries_dao.repository, 'find', return_value=fake_time_entry
dao_get_mock = mocker.patch.object(
time_entries_dao, 'get', return_value={}
)

valid_id = fake.random_int(1, 9999)
Expand All @@ -179,9 +179,7 @@ def test_get_time_entry_should_succeed_with_valid_id(

assert HTTPStatus.OK == response.status_code
fake_time_entry == json.loads(response.data)
repository_find_mock.assert_called_once_with(
str(valid_id), ANY, peeker=ANY
)
dao_get_mock.assert_called_once_with(str(valid_id))


def test_get_time_entry_should_response_with_unprocessable_entity_for_invalid_id_format(
Expand Down Expand Up @@ -614,20 +612,15 @@ def test_find_all_is_called_with_generated_dates(
time_entries_dao,
)

repository_find_all_mock = mocker.patch.object(
time_entries_dao.repository, 'find_all', return_value=[]
dao_get_all_mock = mocker.patch.object(
time_entries_dao, 'get_all', return_value=[]
)

response = client.get(url, headers=valid_header, follow_redirects=True)

date_range = get_date_range_of_month(year, month)
conditions = {'owner_id': owner_id}

assert HTTPStatus.OK == response.status_code
assert json.loads(response.data) is not None
repository_find_all_mock.assert_called_once_with(
ANY, conditions=conditions, date_range=date_range
)
dao_get_all_mock.assert_called_once()


def test_summary_is_called_with_date_range_from_worked_time_module(
Expand Down
39 changes: 13 additions & 26 deletions time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,6 @@ def create_sql_date_range_filter(date_range: dict) -> str:
else:
return ''

def find(
self,
id: str,
event_context: EventContext,
peeker: Callable = None,
visible_only=True,
mapper: Callable = None,
):
time_entry = CosmosDBRepository.find(
self, id, event_context, peeker, visible_only, mapper,
)

project_dao = projects_model.create_dao()
project = project_dao.get(time_entry.project_id)
setattr(time_entry, 'project_name', project.name)

return time_entry

def find_all(
self,
event_context: EventContext,
Expand All @@ -141,19 +123,14 @@ def find_all(

custom_params = self.generate_params(date_range)

time_entries = CosmosDBRepository.find_all(
return CosmosDBRepository.find_all(
self,
event_context=event_context,
conditions=conditions,
custom_sql_conditions=custom_sql_conditions,
custom_params=custom_params,
)

project_dao = projects_model.create_dao()
projects = project_dao.get_all()
add_project_name_to_time_entries(time_entries, projects)
return time_entries

def on_create(self, new_item_data: dict, event_context: EventContext):
CosmosDBRepository.on_create(self, new_item_data, event_context)

Expand Down Expand Up @@ -310,16 +287,26 @@ def get_all(self, conditions: dict = {}) -> list:
conditions.update({"owner_id": event_ctx.user_id})

date_range = self.handle_date_filter_args(args=conditions)
return self.repository.find_all(
time_entries = self.repository.find_all(
event_ctx, conditions=conditions, date_range=date_range
)

project_dao = projects_model.create_dao()
projects = project_dao.get_all()
add_project_name_to_time_entries(time_entries, projects)
return time_entries

def get(self, id):
event_ctx = self.create_event_context("read")
return self.repository.find(
time_entry = self.repository.find(
id, event_ctx, peeker=self.check_whether_current_user_owns_item
)

project_dao = projects_model.create_dao()
project = project_dao.get(time_entry.project_id)
setattr(time_entry, 'project_name', project.name)
return time_entry

def create(self, data: dict):
event_ctx = self.create_event_context("create")
data['owner_id'] = event_ctx.user_id
Expand Down