@@ -230,6 +230,95 @@ def test_get_time_entry_should_succeed_with_valid_id(
230
230
'current_user_is_tester, expected_user_ids' ,
231
231
[
232
232
(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
+ [
233
322
(False , ['id1' , 'id1' ]),
234
323
],
235
324
)
@@ -239,7 +328,7 @@ def test_get_time_entry_should_succeed_with_valid_id(
239
328
@patch (
240
329
'commons.feature_toggles.feature_toggle_manager.FeatureToggleManager.is_toggle_enabled_for_user'
241
330
)
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 (
243
332
is_toggle_enabled_for_user_mock ,
244
333
get_azure_app_configuration_client_mock ,
245
334
get_test_user_ids_mock ,
@@ -284,7 +373,7 @@ def test_get_time_entries_by_type_of_user(
284
373
"/time-entries?user_id=*" , headers = valid_header , follow_redirects = True
285
374
)
286
375
287
- is_test_user_mock .assert_called ()
376
+ get_test_user_ids_mock .assert_called ()
288
377
find_all_mock .assert_called ()
289
378
290
379
expected_user_ids_in_time_entries = expected_user_ids
0 commit comments