Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
refactor(api): enable strict typing for workspace permission tests (#43875)
CodeAlex7c24bd02e78c
diff --git a/api/tests/unit_tests/libs/test_workspace_permission.py b/api/tests/unit_tests/libs/test_workspace_permission.pyindex 1f6d7dfeec6..b19b0412c70 100644--- a/api/tests/unit_tests/libs/test_workspace_permission.py+++ b/api/tests/unit_tests/libs/test_workspace_permission.py@@ -1,5 +1,6 @@import logging-from unittest.mock import patch+from collections.abc import Callable+from unittest.mock import Mock, patchimport pytestfrom werkzeug.exceptions import Forbidden@@ -16,7 +17,9 @@ class TestWorkspacePermissionHelper:"""Test workspace permission helper functions."""@patch("libs.workspace_permission.EnterpriseService")- def test_community_edition_allows_invite(self, mock_enterprise_service, config_overrides):+ def test_community_edition_allows_invite(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""Community edition should always allow invitations without calling any service."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.COMMUNITY)@@ -26,7 +29,7 @@ class TestWorkspacePermissionHelper:# EnterpriseService should NOT be called in community editionmock_enterprise_service.WorkspacePermissionService.get_permission.assert_not_called()- def test_community_edition_allows_transfer(self, config_overrides):+ def test_community_edition_allows_transfer(self, config_overrides: Callable[..., None]) -> None:"""Community edition should check billing plan but not call enterprise service."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.COMMUNITY)@@ -34,7 +37,9 @@ class TestWorkspacePermissionHelper:check_workspace_owner_transfer_permission("test-workspace-id", owner_transfer_allowed=True)@patch("libs.workspace_permission.EnterpriseService")- def test_enterprise_blocks_invite_when_disabled(self, mock_enterprise_service, config_overrides):+ def test_enterprise_blocks_invite_when_disabled(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""Enterprise edition should block invitations when workspace policy is False."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)@@ -47,7 +52,9 @@ class TestWorkspacePermissionHelper:mock_enterprise_service.WorkspacePermissionService.get_permission.assert_called_once_with("test-workspace-id")@patch("libs.workspace_permission.EnterpriseService")- def test_enterprise_allows_invite_when_enabled(self, mock_enterprise_service, config_overrides):+ def test_enterprise_allows_invite_when_enabled(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""Enterprise edition should allow invitations when workspace policy is True."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)@@ -60,7 +67,9 @@ class TestWorkspacePermissionHelper:mock_enterprise_service.WorkspacePermissionService.get_permission.assert_called_once_with("test-workspace-id")@patch("libs.workspace_permission.EnterpriseService")- def test_billing_plan_blocks_transfer(self, mock_enterprise_service, config_overrides):+ def test_billing_plan_blocks_transfer(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""SANDBOX billing plan should block owner transfer before checking enterprise policy."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)with pytest.raises(Forbidden, match="Your current plan does not allow workspace ownership transfer"):@@ -70,7 +79,9 @@ class TestWorkspacePermissionHelper:mock_enterprise_service.WorkspacePermissionService.get_permission.assert_not_called()@patch("libs.workspace_permission.EnterpriseService")- def test_enterprise_blocks_transfer_when_disabled(self, mock_enterprise_service, config_overrides):+ def test_enterprise_blocks_transfer_when_disabled(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""Enterprise edition should block transfer when workspace policy is False."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)mock_permission = WorkspacePermission(workspaceId="test-workspace-id", allowOwnerTransfer=False)@@ -82,7 +93,9 @@ class TestWorkspacePermissionHelper:mock_enterprise_service.WorkspacePermissionService.get_permission.assert_called_once_with("test-workspace-id")@patch("libs.workspace_permission.EnterpriseService")- def test_enterprise_allows_transfer_when_both_enabled(self, mock_enterprise_service, config_overrides):+ def test_enterprise_allows_transfer_when_both_enabled(+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None]+ ) -> None:"""Enterprise edition should allow transfer when both billing and workspace policy allow."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)mock_permission = WorkspacePermission(workspaceId="test-workspace-id", allowOwnerTransfer=True)@@ -95,8 +108,8 @@ class TestWorkspacePermissionHelper:@patch("libs.workspace_permission.EnterpriseService")def test_enterprise_service_error_fails_open(- self, mock_enterprise_service, config_overrides, caplog: pytest.LogCaptureFixture- ):+ self, mock_enterprise_service: Mock, config_overrides: Callable[..., None], caplog: pytest.LogCaptureFixture+ ) -> None:"""On enterprise service error, should fail-open (allow) and log error."""config_overrides(DEPLOYMENT_EDITION=DeploymentEdition.ENTERPRISE)diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.tomlindex 9ca8fcb23da..af4233b4e82 100644--- a/api/tests/unit_tests/pyrefly.toml+++ b/api/tests/unit_tests/pyrefly.toml@@ -658,7 +658,6 @@ project-excludes = ["libs/test_token.py","libs/test_token_manager.py","libs/test_uuid_utils.py",- "libs/test_workspace_permission.py","libs/test_yarl.py","migrations/test_uuidv7_pg18_migration.py","models/test_account_models.py",