@@ -85,6 +85,7 @@ def get_app_sp_graph_data_mock():
85
85
]
86
86
}
87
87
88
+
88
89
@pytest .fixture
89
90
def workspace_with_groups ():
90
91
return Workspace (
@@ -105,6 +106,7 @@ def workspace_with_groups():
105
106
}
106
107
)
107
108
109
+
108
110
@pytest .fixture
109
111
def workspace_without_groups ():
110
112
return Workspace (
@@ -125,14 +127,17 @@ def workspace_without_groups():
125
127
}
126
128
)
127
129
130
+
128
131
@pytest .fixture
129
132
def role_owner ():
130
133
return Role (id = "owner-role-id" , value = "WorkspaceOwner" , isEnabled = True , description = "Owner" , displayName = "Owner" , origin = "" , allowedMemberTypes = [])
131
134
135
+
132
136
@pytest .fixture
133
137
def user_without_role ():
134
138
return User (
id = "user1" ,
name = "Test User" ,
email = "[email protected] " ,
roles = [])
135
139
140
+
136
141
@pytest .fixture
137
142
def user_with_role ():
138
143
return User (
id = "user2" ,
name = "Test User 2" ,
email = "[email protected] " ,
roles = [
"WorkspaceOwner" ])
@@ -654,21 +659,6 @@ def test_get_workspace_role_by_name(mock_ms_graph_query):
654
659
655
660
@patch ("services.aad_authentication.AzureADAuthorization.get_user_by_email" )
656
661
def test_get_user_by_email (mock_get_user_by_email ):
657
- workspace = Workspace (
658
- id = "abc" ,
659
- etag = "" ,
660
- templateName = "template-name" ,
661
- templateVersion = "0.1.0" ,
662
- resourcePath = "test" ,
663
- properties = {
664
- "client_id" : "1234" ,
665
- "sp_id" : "abc127" ,
666
- "app_role_id_workspace_owner" : "abc128" ,
667
- "app_role_id_workspace_researcher" : "abc129" ,
668
- "app_role_id_workspace_airlock_manager" : "abc130" ,
669
- },
670
- )
671
-
672
662
mock_get_user_by_email .
return_value = User (
id = "1" ,
name = "John Doe" ,
email = "[email protected] " ,
roles = [
"WorkspaceOwner" ])
673
663
674
664
access_service = AzureADAuthorization ()
@@ -754,6 +744,7 @@ def get_mock_role_response(principal_roles):
754
744
)
755
745
return response
756
746
747
+
757
748
@patch ("services.aad_authentication.AzureADAuthorization._is_user_in_role" , return_value = True )
758
749
@patch ("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use" )
759
750
@patch ("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application_group" )
@@ -769,12 +760,13 @@ def test_assign_workspace_user_already_has_role(workspace_role_in_use_mock,
769
760
assert assign_user_to_group_mock .call_count == 0
770
761
assert assign_user_to_role_mock .call_count == 0
771
762
763
+
772
764
@patch ("services.aad_authentication.AzureADAuthorization._is_user_in_role" , return_value = False )
773
765
@patch ("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use" , return_value = False )
774
766
@patch ("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application_group" )
775
767
@patch ("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application" )
776
768
def test_assign_workspace_user_if_no_groups (assign_user_to_role_mock ,assign_user_to_group_mock ,
777
- workspace_without_groups , role_owner ,
769
+ workspace_without_groups , role_owner ,
778
770
user_with_role ):
779
771
780
772
access_service = AzureADAuthorization ()
@@ -785,12 +777,13 @@ def test_assign_workspace_user_if_no_groups(assign_user_to_role_mock,assign_user
785
777
assert assign_user_to_group_mock .call_count == 0
786
778
assert assign_user_to_role_mock .call_count == 1
787
779
780
+
788
781
@patch ("services.aad_authentication.AzureADAuthorization._is_user_in_role" , return_value = False )
789
782
@patch ("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use" , return_value = True )
790
783
@patch ("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application_group" )
791
784
@patch ("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application" )
792
785
def test_assign_workspace_user_if_groups (assign_user_to_role_mock ,assign_user_to_group_mock ,
793
- workspace_without_groups , role_owner ,
786
+ workspace_without_groups , role_owner ,
794
787
user_with_role ):
795
788
796
789
access_service = AzureADAuthorization ()
@@ -801,12 +794,13 @@ def test_assign_workspace_user_if_groups(assign_user_to_role_mock,assign_user_to
801
794
assert assign_user_to_group_mock .call_count == 1
802
795
assert assign_user_to_role_mock .call_count == 0
803
796
797
+
804
798
@patch ("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use" , return_value = False )
805
799
@patch ("services.aad_authentication.AzureADAuthorization._remove_workspace_user_from_application_group" )
806
800
@patch ("services.aad_authentication.AzureADAuthorization._remove_workspace_user_from_application" )
807
801
@patch ("services.aad_authentication.AzureADAuthorization._get_role_assignment_for_user" )
808
802
def test_remove_workspace_user_if_no_groups (get_role_assignment_mock ,
809
- remove_user_to_role_mock ,remove_user_to_group_mock ,
803
+ remove_user_to_role_mock , remove_user_to_group_mock ,
810
804
workspace_without_groups , role_owner ,
811
805
user_with_role ):
812
806
@@ -819,12 +813,13 @@ def test_remove_workspace_user_if_no_groups(get_role_assignment_mock,
819
813
assert remove_user_to_group_mock .call_count == 0
820
814
assert remove_user_to_role_mock .call_count == 1
821
815
816
+
822
817
@patch ("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use" , return_value = True )
823
818
@patch ("services.aad_authentication.AzureADAuthorization._remove_workspace_user_from_application_group" )
824
819
@patch ("services.aad_authentication.AzureADAuthorization._remove_workspace_user_from_application" )
825
820
@patch ("services.aad_authentication.AzureADAuthorization._get_role_assignment_for_user" )
826
821
def test_remove_workspace_user_if_groups (get_role_assignment_mock ,
827
- remove_user_to_role_mock ,remove_user_to_group_mock ,
822
+ remove_user_to_role_mock , remove_user_to_group_mock ,
828
823
workspace_without_groups , role_owner ,
829
824
user_with_role ):
830
825
@@ -865,6 +860,7 @@ def test_get_assignable_users_returns_users(_, request_get_mock, mock_headers):
865
860
assert users [0 ].name == "User 1"
866
861
assert users [
0 ].
email == "[email protected] "
867
862
863
+
868
864
@patch ("services.aad_authentication.AzureADAuthorization._get_msgraph_token" , return_value = "token" )
869
865
@patch ("services.aad_authentication.AzureADAuthorization._ms_graph_query" )
870
866
@patch ("services.aad_authentication.AzureADAuthorization._get_auth_header" )
@@ -882,8 +878,8 @@ def test_get_workspace_roles_returns_roles(_, ms_graph_query_mock, mock_headers,
882
878
Role (id = 1 , value = "AirlockManager" , isEnabled = True , description = "" , displayName = "Airlock Manager" , origin = "" , allowedMemberTypes = []).dict (),
883
879
Role (id = 2 , value = "WorkspaceResearcher" , isEnabled = True , description = "" , displayName = "Workspace Researcher" , origin = "" , allowedMemberTypes = []).dict (),
884
880
Role (id = 3 , value = "WorkspaceOwner" , isEnabled = True , description = "" , displayName = "Workspace Owner" , origin = "" , allowedMemberTypes = []).dict (),
885
- ]
886
- }
881
+ ]
882
+ }
887
883
ms_graph_query_mock .return_value = request_get_mock_response
888
884
roles = access_service .get_workspace_roles (workspace_without_groups )
889
885
0 commit comments