Skip to content

Commit c1879ab

Browse files
PabloPablo
authored andcommitted
fix: TT-219 automatic code formating
1 parent 732d19d commit c1879ab

File tree

3 files changed

+105
-10
lines changed

3 files changed

+105
-10
lines changed

tests/time_tracker_api/time_entries/time_entries_model_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ def test_find_all_v2(
324324
time_entry_repository.container = Mock()
325325
time_entry_repository.container.query_items = query_items_mock
326326

327-
time_entry_repository.add_complementary_info = Mock()
328327
time_entry_repository.add_complementary_info = query_items_mock
329328

330329
result = time_entry_repository.find_all(
@@ -371,7 +370,9 @@ def test_get_last_entry(
371370
time_entry_repository.container = Mock()
372371
time_entry_repository.container.query_items = query_items_mock
373372

374-
time_entry = time_entry_repository.get_last_entry('id1', ['id1'], event_context)
373+
time_entry = time_entry_repository.get_last_entry(
374+
'id1', ['id1'], event_context
375+
)
375376

376377
find_partition_key_value_mock.assert_called_once()
377378
assert isinstance(time_entry, TimeEntryCosmosDBModel)

tests/time_tracker_api/time_entries/time_entries_namespace_test.py

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,95 @@ def test_get_time_entry_should_succeed_with_valid_id(
230230
'current_user_is_tester, expected_user_ids',
231231
[
232232
(True, ['id1', 'id1']),
233+
],
234+
)
235+
@patch(
236+
'commons.feature_toggles.feature_toggle_manager.FeatureToggleManager.get_azure_app_configuration_client'
237+
)
238+
@patch(
239+
'commons.feature_toggles.feature_toggle_manager.FeatureToggleManager.is_toggle_enabled_for_user'
240+
)
241+
def test_get_time_entries_by_type_of_user_when_is_user_tester(
242+
is_toggle_enabled_for_user_mock,
243+
get_azure_app_configuration_client_mock,
244+
get_test_user_ids_mock,
245+
is_test_user_mock,
246+
client: FlaskClient,
247+
valid_header: dict,
248+
time_entries_dao,
249+
current_user_is_tester,
250+
expected_user_ids,
251+
):
252+
is_toggle_enabled_for_user_mock.return_value = True
253+
test_user_id = "id1"
254+
non_test_user_id = "id2"
255+
te1 = TimeEntryCosmosDBModel(
256+
{
257+
"id": '1',
258+
"project_id": "1",
259+
"owner_id": test_user_id,
260+
"tenant_id": '1',
261+
"start_date": "",
262+
}
263+
)
264+
te2 = TimeEntryCosmosDBModel(
265+
{
266+
"id": '2',
267+
"project_id": "2",
268+
"owner_id": test_user_id,
269+
"tenant_id": '2',
270+
"start_date": "",
271+
}
272+
)
273+
274+
find_all_mock = Mock()
275+
find_all_mock.return_value = [te1, te2]
276+
277+
time_entries_dao.repository.find_all = find_all_mock
278+
279+
is_test_user_mock.return_value = current_user_is_tester
280+
281+
response = client.get(
282+
"/time-entries?user_id=*", headers=valid_header, follow_redirects=True
283+
)
284+
285+
get_test_user_ids_mock.assert_not_called()
286+
find_all_mock.assert_called()
287+
288+
expected_user_ids_in_time_entries = expected_user_ids
289+
actual_user_ids_in_time_entries = [
290+
time_entry["owner_id"] for time_entry in json.loads(response.data)
291+
]
292+
assert expected_user_ids_in_time_entries == actual_user_ids_in_time_entries
293+
294+
295+
@patch(
296+
'time_tracker_api.time_entries.time_entries_dao.TimeEntriesCosmosDBDao.create_event_context',
297+
Mock(),
298+
)
299+
@patch(
300+
'time_tracker_api.time_entries.time_entries_dao.TimeEntriesCosmosDBDao.build_custom_query',
301+
Mock(),
302+
)
303+
@patch(
304+
'time_tracker_api.time_entries.time_entries_dao.TimeEntriesCosmosDBDao.handle_date_filter_args',
305+
Mock(),
306+
)
307+
@patch(
308+
'time_tracker_api.time_entries.time_entries_repository.TimeEntryCosmosDBRepository.create_sql_date_range_filter',
309+
Mock(),
310+
)
311+
@patch(
312+
'commons.data_access_layer.cosmos_db.CosmosDBRepository.generate_params',
313+
Mock(),
314+
)
315+
@patch('msal.ConfidentialClientApplication', Mock())
316+
@patch('utils.azure_users.AzureConnection.get_token', Mock())
317+
@patch('utils.azure_users.AzureConnection.is_test_user')
318+
@patch('utils.azure_users.AzureConnection.get_test_user_ids')
319+
@pytest.mark.parametrize(
320+
'current_user_is_tester, expected_user_ids',
321+
[
233322
(False, ['id1', 'id1']),
234323
],
235324
)
@@ -239,7 +328,7 @@ def test_get_time_entry_should_succeed_with_valid_id(
239328
@patch(
240329
'commons.feature_toggles.feature_toggle_manager.FeatureToggleManager.is_toggle_enabled_for_user'
241330
)
242-
def test_get_time_entries_by_type_of_user(
331+
def test_get_time_entries_by_type_of_user_when_is_not_user_tester(
243332
is_toggle_enabled_for_user_mock,
244333
get_azure_app_configuration_client_mock,
245334
get_test_user_ids_mock,
@@ -284,7 +373,7 @@ def test_get_time_entries_by_type_of_user(
284373
"/time-entries?user_id=*", headers=valid_header, follow_redirects=True
285374
)
286375

287-
is_test_user_mock.assert_called()
376+
get_test_user_ids_mock.assert_called()
288377
find_all_mock.assert_called()
289378

290379
expected_user_ids_in_time_entries = expected_user_ids

time_tracker_api/time_entries/time_entries_repository.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010

1111
from utils.time import current_datetime_str
12+
from utils.repository import convert_list_to_tuple_string
1213

1314
from utils.extend_model import (
1415
add_project_info_to_time_entries,
@@ -290,9 +291,9 @@ def find_all(
290291

291292
def create_sql_test_users_exclusion_condition(self, test_user_ids):
292293
if test_user_ids != None:
293-
return (
294-
" AND c.owner_id NOT IN ('" + "','".join(test_user_ids) + "') "
295-
)
294+
tuple_string = convert_list_to_tuple_string(test_user_ids)
295+
return "AND c.owner_id NOT IN {list}".format(list=tuple_string)
296+
296297
return ""
297298

298299
def get_last_entry(
@@ -321,12 +322,16 @@ def get_last_entry(
321322
function_mapper = self.get_mapper_or_dict(mapper)
322323
return function_mapper(next(result))
323324

324-
325325
def update_last_entry(
326-
self, owner_id: str, start_date: str, id_running_entry: str, event_context: EventContext
326+
self,
327+
owner_id: str,
328+
start_date: str,
329+
id_running_entry: str,
330+
event_context: EventContext,
327331
):
328332
last_entry = self.get_last_entry(
329-
owner_id, id_running_entry, event_context)
333+
owner_id, id_running_entry, event_context
334+
)
330335
end_date = str_to_datetime(last_entry.end_date)
331336
_start_date = str_to_datetime(start_date)
332337

0 commit comments

Comments
 (0)