Skip to content

Commit 5394265

Browse files
committed
fix: Resolve conflicts #122
2 parents 1e72830 + 56af879 commit 5394265

File tree

4 files changed

+27
-42
lines changed

4 files changed

+27
-42
lines changed

commons/data_access_layer/cosmos_db.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def find(
210210
self,
211211
id: str,
212212
event_context: EventContext,
213-
peeker: 'function' = None,
213+
peeker: Callable = None,
214214
visible_only=True,
215215
mapper: Callable = None,
216216
):
@@ -268,7 +268,7 @@ def partial_update(
268268
id: str,
269269
changes: dict,
270270
event_context: EventContext,
271-
peeker: 'function' = None,
271+
peeker: Callable = None,
272272
visible_only=True,
273273
mapper: Callable = None,
274274
):
@@ -298,7 +298,7 @@ def delete(
298298
self,
299299
id: str,
300300
event_context: EventContext,
301-
peeker: 'function' = None,
301+
peeker: Callable = None,
302302
mapper: Callable = None,
303303
):
304304
return self.partial_update(
@@ -341,7 +341,9 @@ def __init__(self, repository: CosmosDBRepository):
341341
def get_all(self, conditions: dict = None, **kwargs) -> list:
342342
conditions = conditions if conditions else {}
343343
event_ctx = self.create_event_context("read-many")
344-
return self.repository.find_all(event_ctx, conditions=conditions, **kwargs)
344+
return self.repository.find_all(
345+
event_ctx, conditions=conditions, **kwargs
346+
)
345347

346348
def get(self, id):
347349
event_ctx = self.create_event_context("read")
@@ -399,6 +401,7 @@ def generate_uuid4() -> str:
399401

400402
def get_last_day_of_month(year: int, month: int) -> int:
401403
from calendar import monthrange
404+
402405
return monthrange(year=year, month=month)[1]
403406

404407

@@ -412,7 +415,9 @@ def get_current_month() -> int:
412415

413416
def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
414417
first_day_of_month = 1
415-
start_date = datetime(year=year, month=month, day=first_day_of_month,tzinfo=timezone.utc)
418+
start_date = datetime(
419+
year=year, month=month, day=first_day_of_month, tzinfo=timezone.utc
420+
)
416421

417422
last_day_of_month = get_last_day_of_month(year=year, month=month)
418423
end_date = datetime(
@@ -423,7 +428,7 @@ def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
423428
minute=59,
424429
second=59,
425430
microsecond=999999,
426-
tzinfo=timezone.utc
431+
tzinfo=timezone.utc,
427432
)
428433

429434
return {

tests/time_tracker_api/time_entries/time_entries_namespace_test.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def test_list_all_time_entries(
146146
time_entries_dao,
147147
)
148148

149-
repository_find_all_mock = mocker.patch.object(
150-
time_entries_dao.repository, 'find_all', return_value=[]
149+
dao_get_all_mock = mocker.patch.object(
150+
time_entries_dao, 'get_all', return_value=[]
151151
)
152152

153153
response = client.get(
@@ -156,7 +156,7 @@ def test_list_all_time_entries(
156156

157157
assert HTTPStatus.OK == response.status_code
158158
assert [] == json.loads(response.data)
159-
repository_find_all_mock.assert_called_once()
159+
dao_get_all_mock.assert_called_once()
160160

161161

162162
def test_get_time_entry_should_succeed_with_valid_id(
@@ -166,8 +166,8 @@ def test_get_time_entry_should_succeed_with_valid_id(
166166
time_entries_dao,
167167
)
168168

169-
repository_find_mock = mocker.patch.object(
170-
time_entries_dao.repository, 'find', return_value=fake_time_entry
169+
dao_get_mock = mocker.patch.object(
170+
time_entries_dao, 'get', return_value={}
171171
)
172172

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

180180
assert HTTPStatus.OK == response.status_code
181181
fake_time_entry == json.loads(response.data)
182-
repository_find_mock.assert_called_once_with(
183-
str(valid_id), ANY, peeker=ANY
184-
)
182+
dao_get_mock.assert_called_once_with(str(valid_id))
185183

186184

187185
def test_get_time_entry_should_response_with_unprocessable_entity_for_invalid_id_format(
@@ -614,20 +612,15 @@ def test_find_all_is_called_with_generated_dates(
614612
time_entries_dao,
615613
)
616614

617-
repository_find_all_mock = mocker.patch.object(
618-
time_entries_dao.repository, 'find_all', return_value=[]
615+
dao_get_all_mock = mocker.patch.object(
616+
time_entries_dao, 'get_all', return_value=[]
619617
)
620618

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

623-
date_range = get_date_range_of_month(year, month)
624-
conditions = {'owner_id': owner_id}
625-
626621
assert HTTPStatus.OK == response.status_code
627622
assert json.loads(response.data) is not None
628-
repository_find_all_mock.assert_called_once_with(
629-
ANY, conditions=conditions, date_range=date_range
630-
)
623+
dao_get_all_mock.assert_called_once()
631624

632625

633626
def test_summary_is_called_with_date_range_from_worked_time_module(

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,6 @@ def create_sql_date_range_filter(date_range: dict) -> str:
120120
else:
121121
return ''
122122

123-
def find(
124-
self,
125-
id: str,
126-
event_context: EventContext,
127-
peeker: 'function' = None,
128-
visible_only=True,
129-
mapper: Callable = None,
130-
):
131-
time_entry = CosmosDBRepository.find(
132-
self, id, event_context, peeker, visible_only, mapper,
133-
)
134-
135-
project_dao = projects_model.create_dao()
136-
project = project_dao.get(time_entry.project_id)
137-
setattr(time_entry, 'project_name', project.name)
138-
139-
return time_entry
140-
141123
def find_all(
142124
self,
143125
event_context: EventContext,
@@ -334,10 +316,15 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
334316

335317
def get(self, id):
336318
event_ctx = self.create_event_context("read")
337-
return self.repository.find(
319+
time_entry = self.repository.find(
338320
id, event_ctx, peeker=self.check_whether_current_user_owns_item
339321
)
340322

323+
project_dao = projects_model.create_dao()
324+
project = project_dao.get(time_entry.project_id)
325+
setattr(time_entry, 'project_name', project.name)
326+
return time_entry
327+
341328
def create(self, data: dict):
342329
event_ctx = self.create_event_context("create")
343330
data['owner_id'] = event_ctx.user_id

time_tracker_api/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.12.1'
1+
__version__ = '0.12.2'

0 commit comments

Comments
 (0)