@@ -54,7 +54,13 @@ def mock_current_robot() -> RobotAccountDetails:
5454
5555
5656@pytest .fixture
57- def mock_quay_api_store () -> dict [OrgKey , OrgInfo ]:
57+ def mock_quay_api () -> QuayApi :
58+ """Mock QuayApi"""
59+ return create_autospec (QuayApi )
60+
61+
62+ @pytest .fixture
63+ def mock_quay_api_store (mock_quay_api : QuayApi ) -> dict [OrgKey , OrgInfo ]:
5864 """Mock QuayApiStore"""
5965 return {
6066 OrgKey ("quay-instance" , "test-org" ): OrgInfo (
@@ -64,7 +70,7 @@ def mock_quay_api_store() -> dict[OrgKey, OrgInfo]:
6470 managedRepos = False ,
6571 mirror = None ,
6672 mirror_filters = {},
67- api = create_autospec ( QuayApi ) ,
73+ api = mock_quay_api ,
6874 )
6975 }
7076
@@ -320,7 +326,9 @@ def test_calculate_diff_no_changes() -> None:
320326 assert len (actions ) == 0
321327
322328
323- def test_get_current_robot_accounts_success (mock_quay_api_store : QuayApiStore ) -> None :
329+ def test_get_current_robot_accounts_success (
330+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
331+ ) -> None :
324332 """Test successful fetching of current robot accounts"""
325333 mock_robots = [
326334 RobotAccountDetails (
@@ -336,8 +344,8 @@ def test_get_current_robot_accounts_success(mock_quay_api_store: QuayApiStore) -
336344 repositories = [{"name" : "repo2" , "role" : "write" }],
337345 ),
338346 ]
339- mock_api = mock_quay_api_store [ next ( iter ( mock_quay_api_store . keys ()))][ "api" ]
340- mock_api .list_robot_accounts .return_value = mock_robots # type: ignore
347+
348+ mock_quay_api .list_robot_accounts .return_value = mock_robots # type: ignore
341349
342350 result = get_current_robot_accounts (mock_quay_api_store )
343351
@@ -347,19 +355,21 @@ def test_get_current_robot_accounts_success(mock_quay_api_store: QuayApiStore) -
347355
348356
349357def test_get_current_robot_accounts_exception (
358+ mock_quay_api : QuayApi ,
350359 mock_quay_api_store : QuayApiStore ,
351360) -> None :
352361 """Test handling of exceptions when fetching robot accounts"""
353- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
354- mock_api .list_robot_accounts .side_effect = Exception ("API Error" ) # type: ignore
362+ mock_quay_api .list_robot_accounts .side_effect = Exception ("API Error" ) # type: ignore
355363
356364 result = get_current_robot_accounts (mock_quay_api_store )
357365
358366 assert len (result ) == 1
359367 assert result ["quay-instance" , "test-org" ] == []
360368
361369
362- def test_apply_action_create_robot (mock_quay_api_store : QuayApiStore ) -> None :
370+ def test_apply_action_create_robot (
371+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
372+ ) -> None :
363373 """Test applying create robot action"""
364374 action = RobotAccountAction (
365375 action = RobotAccountActionType .CREATE ,
@@ -370,11 +380,12 @@ def test_apply_action_create_robot(mock_quay_api_store: QuayApiStore) -> None:
370380
371381 apply_action (action , mock_quay_api_store , dry_run = False )
372382
373- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
374- mock_api .create_robot_account .assert_called_once_with ("new-robot" , "" ) # type: ignore
383+ mock_quay_api .create_robot_account .assert_called_once_with ("new-robot" , "" ) # type: ignore
375384
376385
377- def test_apply_action_delete_robot (mock_quay_api_store : QuayApiStore ) -> None :
386+ def test_apply_action_delete_robot (
387+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
388+ ) -> None :
378389 """Test applying delete robot action"""
379390 action = RobotAccountAction (
380391 action = RobotAccountActionType .DELETE ,
@@ -385,11 +396,12 @@ def test_apply_action_delete_robot(mock_quay_api_store: QuayApiStore) -> None:
385396
386397 apply_action (action , mock_quay_api_store , dry_run = False )
387398
388- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
389- mock_api .delete_robot_account .assert_called_once_with ("old-robot" ) # type: ignore
399+ mock_quay_api .delete_robot_account .assert_called_once_with ("old-robot" ) # type: ignore
390400
391401
392- def test_apply_action_add_team (mock_quay_api_store : QuayApiStore ) -> None :
402+ def test_apply_action_add_team (
403+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
404+ ) -> None :
393405 """Test applying add team action"""
394406 action = RobotAccountAction (
395407 action = RobotAccountActionType .ADD_TEAM ,
@@ -401,11 +413,12 @@ def test_apply_action_add_team(mock_quay_api_store: QuayApiStore) -> None:
401413
402414 apply_action (action , mock_quay_api_store , dry_run = False )
403415
404- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
405- mock_api .add_user_to_team .assert_called_once_with ("test-org+robot" , "new-team" ) # type: ignore
416+ mock_quay_api .add_user_to_team .assert_called_once_with ("test-org+robot" , "new-team" ) # type: ignore
406417
407418
408- def test_apply_action_remove_team (mock_quay_api_store : QuayApiStore ) -> None :
419+ def test_apply_action_remove_team (
420+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
421+ ) -> None :
409422 """Test applying remove team action"""
410423 action = RobotAccountAction (
411424 action = RobotAccountActionType .REMOVE_TEAM ,
@@ -417,11 +430,14 @@ def test_apply_action_remove_team(mock_quay_api_store: QuayApiStore) -> None:
417430
418431 apply_action (action , mock_quay_api_store , dry_run = False )
419432
420- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
421- mock_api .remove_user_from_team .assert_called_once_with ("test-org+robot" , "old-team" ) # type: ignore
433+ mock_quay_api .remove_user_from_team .assert_called_once_with ( # type: ignore
434+ "test-org+robot" , "old-team"
435+ )
422436
423437
424- def test_apply_action_set_repo_permission (mock_quay_api_store : QuayApiStore ) -> None :
438+ def test_apply_action_set_repo_permission (
439+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
440+ ) -> None :
425441 """Test applying set repository permission action"""
426442 action = RobotAccountAction (
427443 action = RobotAccountActionType .SET_REPO_PERMISSION ,
@@ -434,13 +450,14 @@ def test_apply_action_set_repo_permission(mock_quay_api_store: QuayApiStore) ->
434450
435451 apply_action (action , mock_quay_api_store , dry_run = False )
436452
437- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
438- mock_api .set_repo_robot_account_permissions .assert_called_once_with ( # type: ignore
453+ mock_quay_api .set_repo_robot_account_permissions .assert_called_once_with ( # type: ignore
439454 "repo1" , "robot" , "write"
440455 )
441456
442457
443- def test_apply_action_remove_repo_permission (mock_quay_api_store : QuayApiStore ) -> None :
458+ def test_apply_action_remove_repo_permission (
459+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
460+ ) -> None :
444461 """Test applying remove repository permission action"""
445462 action = RobotAccountAction (
446463 action = RobotAccountActionType .REMOVE_REPO_PERMISSION ,
@@ -452,13 +469,14 @@ def test_apply_action_remove_repo_permission(mock_quay_api_store: QuayApiStore)
452469
453470 apply_action (action , mock_quay_api_store , dry_run = False )
454471
455- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
456- mock_api .delete_repo_robot_account_permissions .assert_called_once_with ( # type: ignore
472+ mock_quay_api .delete_repo_robot_account_permissions .assert_called_once_with ( # type: ignore
457473 "repo1" , "robot"
458474 )
459475
460476
461- def test_apply_action_dry_run (mock_quay_api_store : QuayApiStore ) -> None :
477+ def test_apply_action_dry_run (
478+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
479+ ) -> None :
462480 """Test applying action in dry run mode"""
463481 action = RobotAccountAction (
464482 action = RobotAccountActionType .CREATE ,
@@ -469,11 +487,12 @@ def test_apply_action_dry_run(mock_quay_api_store: QuayApiStore) -> None:
469487
470488 apply_action (action , mock_quay_api_store , dry_run = True )
471489
472- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
473- mock_api .create_robot_account .assert_not_called () # type: ignore
490+ mock_quay_api .create_robot_account .assert_not_called () # type: ignore
474491
475492
476- def test_apply_action_no_org_key (mock_quay_api_store : QuayApiStore ) -> None :
493+ def test_apply_action_no_org_key (
494+ mock_quay_api : QuayApi , mock_quay_api_store : QuayApiStore
495+ ) -> None :
477496 """Test applying action when org key is not found"""
478497 action = RobotAccountAction (
479498 action = RobotAccountActionType .CREATE ,
@@ -484,8 +503,7 @@ def test_apply_action_no_org_key(mock_quay_api_store: QuayApiStore) -> None:
484503
485504 apply_action (action , mock_quay_api_store , dry_run = False )
486505
487- mock_api = mock_quay_api_store [next (iter (mock_quay_api_store .keys ()))]["api" ]
488- mock_api .create_robot_account .assert_not_called () # type: ignore
506+ mock_quay_api .create_robot_account .assert_not_called () # type: ignore
489507
490508
491509def test_apply_action_exception_handling (mock_quay_api_store : QuayApiStore ) -> None :
0 commit comments