Skip to content

Commit

Permalink
more linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Fortunka committed Feb 14, 2025
1 parent c8908e0 commit 9d195a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions api_app/services/aad_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _get_users_inc_groups_from_response(self, users_graph_data, roles_graph_data
if "users" in user_data["body"]["@odata.context"]:
user_email = user_data["body"]["userPrincipalName"]
# if user with id does not already exist in users
user_roles=self._get_roles_for_principal(user_id, roles_graph_data, app_id_to_role_name)
user_roles = self._get_roles_for_principal(user_id, roles_graph_data, app_id_to_role_name)

if not any(user.id == user_id for user in users):
users.append(User(id=user_id, name=user_name, email=user_email, roles=user_roles))
Expand All @@ -297,7 +297,7 @@ def _get_users_inc_groups_from_response(self, users_graph_data, roles_graph_data
user_name = group_member["displayName"]
user_email = group_member["userPrincipalName"]

group_roles=self._get_roles_for_principal(group_id, roles_graph_data, app_id_to_role_name)
group_roles = self._get_roles_for_principal(group_id, roles_graph_data, app_id_to_role_name)

if not any(user.id == user_id for user in users):
users.append(User(id=user_id, name=user_name, email=user_email, roles=group_roles))
Expand Down Expand Up @@ -339,11 +339,11 @@ def get_workspace_roles(self, workspace: Workspace) -> List[Role]:

for role in graph_data["value"]:
roles.append(Role(id=role["id"], value=role["value"],
isEnabled=role["isEnabled"],
description=role["description"],
displayName=role["displayName"],
origin=role["origin"],
allowedMemberTypes=role["allowedMemberTypes"]))
isEnabled=role["isEnabled"],
description=role["description"],
displayName=role["displayName"],
origin=role["origin"],
allowedMemberTypes=role["allowedMemberTypes"]))

return roles

Expand Down
6 changes: 3 additions & 3 deletions api_app/tests_ma/test_api/test_routes/test_workspace_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ async def test_assign_workspace_user_assigns_workspace_user(self, get_workspace_
@patch("api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id", return_value=sample_workspace())
async def test_remove_workspace_user_assignment_removes_workspace_user_assignment(self, get_workspace_by_id_mock, auth_class, app, client):
with patch(f"services.{auth_class}.remove_workspace_role_user_assignment") as remove_workspace_role_user_assignment_mock, \
patch(f"services.{auth_class}.get_user_by_email") as get_user_by_email_mock, \
patch(f"services.{auth_class}.get_workspace_role_by_name") as get_workspace_role_by_name_mock, \
patch(f"services.{auth_class}.get_workspace_users") as get_workspace_users_mock:
patch(f"services.{auth_class}.get_user_by_email") as get_user_by_email_mock, \
patch(f"services.{auth_class}.get_workspace_role_by_name") as get_workspace_role_by_name_mock, \
patch(f"services.{auth_class}.get_workspace_users") as get_workspace_users_mock:

workspace = get_workspace_by_id_mock.return_value

Expand Down
34 changes: 17 additions & 17 deletions api_app/tests_ma/test_services/test_aad_access_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ def test_assign_workspace_user_already_has_role(workspace_role_in_use_mock,
@patch("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use", return_value=False)
@patch("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application_group")
@patch("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application")
def test_assign_workspace_user_if_no_groups(assign_user_to_role_mock,assign_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):
def test_assign_workspace_user_if_no_groups(assign_user_to_role_mock, assign_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):

access_service = AzureADAuthorization()
assign_user_to_role_mock.return_value = None
Expand All @@ -782,9 +782,9 @@ def test_assign_workspace_user_if_no_groups(assign_user_to_role_mock,assign_user
@patch("services.aad_authentication.AzureADAuthorization._is_workspace_role_group_in_use", return_value=True)
@patch("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application_group")
@patch("services.aad_authentication.AzureADAuthorization._assign_workspace_user_to_application")
def test_assign_workspace_user_if_groups(assign_user_to_role_mock,assign_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):
def test_assign_workspace_user_if_groups(assign_user_to_role_mock, assign_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):

access_service = AzureADAuthorization()
assign_user_to_role_mock.return_value = None
Expand All @@ -801,8 +801,8 @@ def test_assign_workspace_user_if_groups(assign_user_to_role_mock,assign_user_to
@patch("services.aad_authentication.AzureADAuthorization._get_role_assignment_for_user")
def test_remove_workspace_user_if_no_groups(get_role_assignment_mock,
remove_user_to_role_mock, remove_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):
workspace_without_groups, role_owner,
user_with_role):

access_service = AzureADAuthorization()
remove_user_to_role_mock.return_value = None
Expand All @@ -819,9 +819,9 @@ def test_remove_workspace_user_if_no_groups(get_role_assignment_mock,
@patch("services.aad_authentication.AzureADAuthorization._remove_workspace_user_from_application")
@patch("services.aad_authentication.AzureADAuthorization._get_role_assignment_for_user")
def test_remove_workspace_user_if_groups(get_role_assignment_mock,
remove_user_to_role_mock, remove_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):
remove_user_to_role_mock, remove_user_to_group_mock,
workspace_without_groups, role_owner,
user_with_role):

access_service = AzureADAuthorization()
remove_user_to_role_mock.return_value = None
Expand All @@ -840,7 +840,7 @@ def test_get_assignable_users_returns_users(_, request_get_mock, mock_headers):
access_service = AzureADAuthorization()

# mock the response of _get_auth_header
headers = {"Authorization": f"Bearer token"}
headers = {"Authorization": "Bearer token"}
mock_headers.return_value = headers
headers["Content-type"] = "application/json"

Expand All @@ -864,22 +864,22 @@ def test_get_assignable_users_returns_users(_, request_get_mock, mock_headers):
@patch("services.aad_authentication.AzureADAuthorization._get_msgraph_token", return_value="token")
@patch("services.aad_authentication.AzureADAuthorization._ms_graph_query")
@patch("services.aad_authentication.AzureADAuthorization._get_auth_header")
def test_get_workspace_roles_returns_roles(_, ms_graph_query_mock, mock_headers,workspace_without_groups):
def test_get_workspace_roles_returns_roles(_, ms_graph_query_mock, mock_headers, workspace_without_groups):
access_service = AzureADAuthorization()

# mock the response of _get_auth_header
headers = {"Authorization": f"Bearer token"}
headers = {"Authorization": "Bearer token"}
mock_headers.return_value = headers
headers["Content-type"] = "application/json"

# Mock the response of the get request
request_get_mock_response = {
"value": [
"value":[
Role(id=1, value="AirlockManager", isEnabled=True, description="", displayName="Airlock Manager", origin="", allowedMemberTypes=[]).dict(),
Role(id=2, value="WorkspaceResearcher", isEnabled=True, description="", displayName="Workspace Researcher", origin="", allowedMemberTypes=[]).dict(),
Role(id=3, value="WorkspaceOwner", isEnabled=True, description="", displayName="Workspace Owner", origin="", allowedMemberTypes=[]).dict(),
]
}
]
}
ms_graph_query_mock.return_value = request_get_mock_response
roles = access_service.get_workspace_roles(workspace_without_groups)

Expand Down

0 comments on commit 9d195a2

Please sign in to comment.