Skip to content

armgit / dify

Public Imported from GitHub
0

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.

test(api): bring account and tool model tests under strict pyrefly (#45628)

yetugef8c99ece942a
diff --git a/api/tests/unit_tests/models/test_account.py b/api/tests/unit_tests/models/test_account.py
index 61987cad94a..a933d7db785 100644
--- a/api/tests/unit_tests/models/test_account.py
+++ b/api/tests/unit_tests/models/test_account.py
@@ -19,13 +19,13 @@ import pytest
from sqlalchemy.orm import Session
from libs.password import compare_password, hash_password, valid_password
-from models.account import Account, AccountStatus, Tenant, TenantAccountJoin, TenantAccountRole
+from models.account import Account, AccountStatus, Tenant, TenantAccountJoin, TenantAccountRole, TenantCustomConfigDict
class TestAccountModelValidation:
"""Test suite for Account model validation and basic operations."""
- def test_account_creation_with_required_fields(self):
+ def test_account_creation_with_required_fields(self) -> None:
"""Test creating an account with all required fields."""
# Arrange & Act
account = Account(
@@ -42,7 +42,7 @@ class TestAccountModelValidation:
assert account.password_salt == "salt_value"
assert account.status == "active" # Default value
- def test_account_creation_with_optional_fields(self):
+ def test_account_creation_with_optional_fields(self) -> None:
"""Test creating an account with optional fields."""
# Arrange & Act
account = Account(
@@ -60,7 +60,7 @@ class TestAccountModelValidation:
assert account.interface_theme == "dark"
assert account.timezone == "America/New_York"
- def test_account_creation_without_password(self):
+ def test_account_creation_without_password(self) -> None:
"""Test creating an account without password (for invite-based registration)."""
# Arrange & Act
account = Account(
@@ -73,7 +73,7 @@ class TestAccountModelValidation:
assert account.password_salt is None
assert not account.is_password_set
- def test_account_is_password_set_property(self):
+ def test_account_is_password_set_property(self) -> None:
"""Test the is_password_set property."""
# Arrange
account_with_password = Account(
@@ -90,7 +90,7 @@ class TestAccountModelValidation:
assert account_with_password.is_password_set
assert not account_without_password.is_password_set
- def test_account_default_status(self):
+ def test_account_default_status(self) -> None:
"""Test that account has default status of 'active'."""
# Arrange & Act
account = Account(
@@ -101,7 +101,7 @@ class TestAccountModelValidation:
# Assert
assert account.status == AccountStatus.ACTIVE
- def test_account_get_status_method(self):
+ def test_account_get_status_method(self) -> None:
"""Test the get_status method returns AccountStatus enum."""
# Arrange
account = Account(
@@ -121,7 +121,7 @@ class TestAccountModelValidation:
class TestPasswordHashingAndVerification:
"""Test suite for password hashing and verification functionality."""
- def test_password_hashing_produces_consistent_result(self):
+ def test_password_hashing_produces_consistent_result(self) -> None:
"""Test that hashing the same password with the same salt produces the same result."""
# Arrange
password = "TestPassword123"
@@ -134,7 +134,7 @@ class TestPasswordHashingAndVerification:
# Assert
assert hash1 == hash2
- def test_password_hashing_different_salts_produce_different_hashes(self):
+ def test_password_hashing_different_salts_produce_different_hashes(self) -> None:
"""Test that different salts produce different hashes for the same password."""
# Arrange
password = "TestPassword123"
@@ -148,7 +148,7 @@ class TestPasswordHashingAndVerification:
# Assert
assert hash1 != hash2
- def test_password_comparison_success(self):
+ def test_password_comparison_success(self) -> None:
"""Test successful password comparison."""
# Arrange
password = "TestPassword123"
@@ -165,7 +165,7 @@ class TestPasswordHashingAndVerification:
# Assert
assert result is True
- def test_password_comparison_failure(self):
+ def test_password_comparison_failure(self) -> None:
"""Test password comparison with wrong password."""
# Arrange
correct_password = "TestPassword123"
@@ -183,7 +183,7 @@ class TestPasswordHashingAndVerification:
# Assert
assert result is False
- def test_valid_password_with_correct_format(self):
+ def test_valid_password_with_correct_format(self) -> None:
"""Test password validation with correct format."""
# Arrange
valid_passwords = [
@@ -198,7 +198,7 @@ class TestPasswordHashingAndVerification:
result = valid_password(password)
assert result == password
- def test_valid_password_with_incorrect_format(self):
+ def test_valid_password_with_incorrect_format(self) -> None:
"""Test password validation with incorrect format."""
# Arrange
invalid_passwords = [
@@ -213,7 +213,7 @@ class TestPasswordHashingAndVerification:
with pytest.raises(ValueError, match="Password must contain letters and numbers"):
valid_password(password)
- def test_password_hashing_integration_with_account(self):
+ def test_password_hashing_integration_with_account(self) -> None:
"""Test password hashing integration with Account model."""
# Arrange
password = "SecurePass123"
@@ -238,7 +238,7 @@ class TestPasswordHashingAndVerification:
class TestAccountStatusTransitions:
"""Test suite for account status transitions."""
- def test_account_status_enum_values(self):
+ def test_account_status_enum_values(self) -> None:
"""Test that AccountStatus enum has all expected values."""
# Assert
assert AccountStatus.PENDING == "pending"
@@ -247,7 +247,7 @@ class TestAccountStatusTransitions:
assert AccountStatus.BANNED == "banned"
assert AccountStatus.CLOSED == "closed"
- def test_account_status_transition_pending_to_active(self):
+ def test_account_status_transition_pending_to_active(self) -> None:
"""Test transitioning account status from pending to active."""
# Arrange
account = Account(
@@ -264,7 +264,7 @@ class TestAccountStatusTransitions:
assert account.get_status() == AccountStatus.ACTIVE
assert account.initialized_at is not None
- def test_account_status_transition_active_to_banned(self):
+ def test_account_status_transition_active_to_banned(self) -> None:
"""Test transitioning account status from active to banned."""
# Arrange
account = Account(
@@ -279,7 +279,7 @@ class TestAccountStatusTransitions:
# Assert
assert account.get_status() == AccountStatus.BANNED
- def test_account_status_transition_active_to_closed(self):
+ def test_account_status_transition_active_to_closed(self) -> None:
"""Test transitioning account status from active to closed."""
# Arrange
account = Account(
@@ -294,7 +294,7 @@ class TestAccountStatusTransitions:
# Assert
assert account.get_status() == AccountStatus.CLOSED
- def test_account_status_uninitialized(self):
+ def test_account_status_uninitialized(self) -> None:
"""Test account with uninitialized status."""
# Arrange & Act
account = Account(
@@ -311,7 +311,7 @@ class TestAccountStatusTransitions:
class TestTenantRelationshipIntegrity:
"""Test suite for tenant relationship integrity."""
- def test_account_current_tenant_id_property(self):
+ def test_account_current_tenant_id_property(self) -> None:
"""Test the current_tenant_id property."""
# Arrange
account = Account(
@@ -335,7 +335,7 @@ class TestTenantRelationshipIntegrity:
# Assert
assert tenant_id_none is None
- def test_current_tenant_is_read_only(self):
+ def test_current_tenant_is_read_only(self) -> None:
"""current_tenant has no setter, so tenant switching cannot open a hidden session."""
account = Account(name="Test User", email="[email protected]")
tenant = Tenant(name="Test Tenant")
@@ -344,7 +344,7 @@ class TestTenantRelationshipIntegrity:
account.current_tenant = tenant # type: ignore[misc]
@pytest.mark.parametrize("sqlite_session", [(Account, Tenant, TenantAccountJoin)], indirect=True)
- def test_set_current_tenant_with_session_uses_caller_session(self, sqlite_session: Session):
+ def test_set_current_tenant_with_session_uses_caller_session(self, sqlite_session: Session) -> None:
account = Account(name="Test User", email="[email protected]")
account.id = str(uuid4())
tenant = Tenant(name="Test Tenant")
@@ -376,7 +376,7 @@ class TestTenantRelationshipIntegrity:
assert account.role == TenantAccountRole.OWNER
@pytest.mark.parametrize("sqlite_session", [(Account, Tenant, TenantAccountJoin)], indirect=True)
- def test_set_tenant_id_with_session_uses_caller_session(self, sqlite_session: Session):
+ def test_set_tenant_id_with_session_uses_caller_session(self, sqlite_session: Session) -> None:
account = Account(name="Test User", email="[email protected]")
account.id = str(uuid4())
decoy_account = Account(name="Decoy User", email="[email protected]")
@@ -415,7 +415,7 @@ class TestAccountRolePermissions:
"""Test suite for account role permissions."""
- def test_is_admin_or_owner_with_admin_role(self):
+ def test_is_admin_or_owner_with_admin_role(self) -> None:
"""Test is_admin_or_owner property with admin role."""
# Arrange
account = Account(
@@ -426,14 +426,14 @@ class TestAccountRolePermissions:
assert account.is_admin_or_owner
- def test_is_admin_or_owner_with_rbac_enabled(self, config_overrides: Callable[..., None]):
+ def test_is_admin_or_owner_with_rbac_enabled(self, config_overrides: Callable[..., None]) -> None:
account = Account(name="Test User", email="[email protected]")
account.role = TenantAccountRole.NORMAL
config_overrides(RBAC_ENABLED=True)
assert account.is_admin_or_owner
- def test_is_admin_or_owner_with_owner_role(self):
+ def test_is_admin_or_owner_with_owner_role(self) -> None:
"""Test is_admin_or_owner property with owner role."""
# Arrange
account = Account(
@@ -445,7 +445,7 @@ class TestAccountRolePermissions:
# Act & Assert
assert account.is_admin_or_owner
- def test_is_admin_or_owner_with_normal_role(self):
+ def test_is_admin_or_owner_with_normal_role(self) -> None:
"""Test is_admin_or_owner property with normal role."""
# Arrange
account = Account(
@@ -457,7 +457,7 @@ class TestAccountRolePermissions:
# Act & Assert
assert not account.is_admin_or_owner
- def test_is_admin_property(self):
+ def test_is_admin_property(self) -> None:
"""Test is_admin property."""
# Arrange
admin_account = Account(name="Admin", email="[email protected]")
@@ -469,14 +469,14 @@ class TestAccountRolePermissions:
assert admin_account.is_admin
assert not owner_account.is_admin
- def test_is_admin_with_rbac_enabled(self, config_overrides: Callable[..., None]):
+ def test_is_admin_with_rbac_enabled(self, config_overrides: Callable[..., None]) -> None:
account = Account(name="Test User", email="[email protected]")
account.role = TenantAccountRole.NORMAL
config_overrides(RBAC_ENABLED=True)
assert account.is_admin
- def test_has_edit_permission_with_editing_roles(self):
+ def test_has_edit_permission_with_editing_roles(self) -> None:
"""Test has_edit_permission property with roles that have edit permission."""
# Arrange
roles_with_edit = [
@@ -491,14 +491,14 @@ class TestAccountRolePermissions:
assert account.has_edit_permission, f"Role {role} should have edit permission"
- def test_has_edit_permission_with_rbac_enabled(self, config_overrides: Callable[..., None]):
+ def test_has_edit_permission_with_rbac_enabled(self, config_overrides: Callable[..., None]) -> None:
account = Account(name="Test User", email="[email protected]")
account.role = TenantAccountRole.NORMAL
config_overrides(RBAC_ENABLED=True)
assert account.has_edit_permission
- def test_has_edit_permission_without_editing_roles(self):
+ def test_has_edit_permission_without_editing_roles(self) -> None:
"""Test has_edit_permission property with roles that don't have edit permission."""
# Arrange
roles_without_edit = [
@@ -512,7 +512,7 @@ class TestAccountRolePermissions:
assert not account.has_edit_permission, f"Role {role} should not have edit permission"
- def test_is_dataset_editor_property(self):
+ def test_is_dataset_editor_property(self) -> None:
"""Test is_dataset_editor property."""
# Arrange
dataset_roles = [
@@ -533,14 +533,14 @@ class TestAccountRolePermissions:
normal_account.role = TenantAccountRole.NORMAL
assert not normal_account.is_dataset_editor
- def test_is_dataset_editor_with_rbac_enabled(self, config_overrides: Callable[..., None]):
+ def test_is_dataset_editor_with_rbac_enabled(self, config_overrides: Callable[..., None]) -> None:
account = Account(name="Test User", email="[email protected]")
account.role = TenantAccountRole.NORMAL
config_overrides(RBAC_ENABLED=True)
assert account.is_dataset_editor
- def test_is_dataset_operator_property(self):
+ def test_is_dataset_operator_property(self) -> None:
"""Test is_dataset_operator property."""
# Arrange
dataset_operator = Account(name="Dataset Operator", email="[email protected]")
@@ -552,14 +552,14 @@ class TestAccountRolePermissions:
assert dataset_operator.is_dataset_operator
assert not normal_account.is_dataset_operator
- def test_is_dataset_operator_with_rbac_enabled(self, config_overrides: Callable[..., None]):
+ def test_is_dataset_operator_with_rbac_enabled(self, config_overrides: Callable[..., None]) -> None:
account = Account(name="Test User", email="[email protected]")
account.role = TenantAccountRole.NORMAL
config_overrides(RBAC_ENABLED=True)
assert account.is_dataset_operator
- def test_current_role_property(self):
+ def test_current_role_property(self) -> None:
"""Test current_role property."""
# Arrange
account = Account(name="Test User", email="[email protected]")
@@ -575,7 +575,7 @@ class TestAccountRolePermissions:
class TestTenantAccountJoinModel:
"""Test suite for TenantAccountJoin model."""
- def test_tenant_account_join_creation(self):
+ def test_tenant_account_join_creation(self) -> None:
"""Test creating a TenantAccountJoin record."""
# Arrange
tenant_id = str(uuid4())
@@ -595,7 +595,7 @@ class TestTenantAccountJoinModel:
assert join.role == TenantAccountRole.NORMAL
assert join.current is True
- def test_tenant_account_join_default_values(self):
+ def test_tenant_account_join_default_values(self) -> None:
"""Test default values for TenantAccountJoin."""
# Arrange
tenant_id = str(uuid4())
@@ -612,7 +612,7 @@ class TestTenantAccountJoinModel:
assert join.role == "normal" # Default value
assert join.invited_by is None # Default value
- def test_tenant_account_join_with_invited_by(self):
+ def test_tenant_account_join_with_invited_by(self) -> None:
"""Test TenantAccountJoin with invited_by field."""
# Arrange
tenant_id = str(uuid4())
@@ -634,7 +634,7 @@ class TestTenantAccountJoinModel:
class TestTenantModel:
"""Test suite for Tenant model."""
- def test_tenant_creation(self):
+ def test_tenant_creation(self) -> None:
"""Test creating a Tenant."""
# Arrange & Act
tenant = Tenant(name="Test Workspace")
@@ -644,20 +644,20 @@ class TestTenantModel:
assert tenant.status == "normal" # Default value
assert tenant.plan == "basic" # Default value
- def test_tenant_custom_config_dict_property(self):
+ def test_tenant_custom_config_dict_property(self) -> None:
"""Test custom_config_dict property getter."""
# Arrange
tenant = Tenant(name="Test Workspace")
- tenant.custom_config = '{"feature1": true, "feature2": "value"}'
+ tenant.custom_config = '{"remove_webapp_brand": true, "replace_webapp_logo": "value"}'
# Act
result = tenant.custom_config_dict
# Assert
- assert result["feature1"] is True
- assert result["feature2"] == "value"
+ assert result["remove_webapp_brand"] is True
+ assert result["replace_webapp_logo"] == "value"
- def test_tenant_custom_config_dict_property_empty(self):
+ def test_tenant_custom_config_dict_property_empty(self) -> None:
"""Test custom_config_dict property with empty config."""
# Arrange
tenant = Tenant(name="Test Workspace")
@@ -669,23 +669,23 @@ class TestTenantModel:
# Assert
assert result == {}
- def test_tenant_custom_config_dict_setter(self):
+ def test_tenant_custom_config_dict_setter(self) -> None:
"""Test custom_config_dict property setter."""
# Arrange
tenant = Tenant(name="Test Workspace")
- config = {"feature1": True, "feature2": "value"}
+ config: TenantCustomConfigDict = {"remove_webapp_brand": True, "replace_webapp_logo": "value"}
# Act
tenant.custom_config_dict = config
# Assert
- assert tenant.custom_config == '{"feature1": true, "feature2": "value"}'
+ assert tenant.custom_config == '{"remove_webapp_brand": true, "replace_webapp_logo": "value"}'
class TestTenantStatusEnum:
"""Test suite for TenantStatus enum."""
- def test_tenant_status_enum_values(self):
+ def test_tenant_status_enum_values(self) -> None:
"""Test TenantStatus enum values."""
# Arrange & Act
from models.account import TenantStatus
@@ -698,7 +698,7 @@ class TestTenantStatusEnum:
class TestAccountIntegration:
"""Integration tests for Account model with related models."""
- def test_account_with_multiple_tenants(self):
+ def test_account_with_multiple_tenants(self) -> None:
"""Test account associated with multiple tenants."""
# Arrange
account = Account(name="Multi-Tenant User", email="[email protected]")
@@ -727,7 +727,7 @@ class TestAccountIntegration:
assert join1.current is True
assert join2.current is False
- def test_account_last_login_tracking(self):
+ def test_account_last_login_tracking(self) -> None:
"""Test account last login tracking."""
# Arrange
account = Account(name="Test User", email="[email protected]")
@@ -742,7 +742,7 @@ class TestAccountIntegration:
assert account.last_login_at == login_time
assert account.last_login_ip == login_ip
- def test_account_initialization_tracking(self):
+ def test_account_initialization_tracking(self) -> None:
"""Test account initialization tracking."""
# Arrange
account = Account(
diff --git a/api/tests/unit_tests/models/test_tools.py b/api/tests/unit_tests/models/test_tools.py
index d767242bec8..61103f66f3c 100644
--- a/api/tests/unit_tests/models/test_tools.py
+++ b/api/tests/unit_tests/models/test_tools.py
@@ -3,6 +3,7 @@ from uuid import uuid4
from sqlalchemy.orm import Session
+from core.plugin.entities.plugin_daemon import CredentialType
from core.tools.entities.tool_entities import ApiProviderSchemaType, ToolProviderType
from models.account import Account, Tenant
from models.model import App, AppMode
@@ -79,7 +80,7 @@ This test suite covers:
class TestBuiltinToolProviderValidation:
"""Test suite for BuiltinToolProvider model validation and operations."""
- def test_builtin_tool_provider_creation_with_required_fields(self):
+ def test_builtin_tool_provider_creation_with_required_fields(self) -> None:
"""Test creating a builtin tool provider with all required fields."""
# Arrange
tenant_id = str(uuid4())
@@ -103,7 +104,7 @@ class TestBuiltinToolProviderValidation:
assert builtin_provider.name == "Google API Key 1"
assert builtin_provider.encrypted_credentials == json.dumps(credentials)
- def test_builtin_tool_provider_credentials_property(self):
+ def test_builtin_tool_provider_credentials_property(self) -> None:
"""Test credentials property parses JSON correctly."""
# Arrange
credentials_data = {
@@ -127,7 +128,7 @@ class TestBuiltinToolProviderValidation:
assert result["api_key"] == "sk-test123"
assert result["auth_type"] == "api_key"
- def test_builtin_tool_provider_credentials_empty_when_none(self):
+ def test_builtin_tool_provider_credentials_empty_when_none(self) -> None:
"""Test credentials property returns empty dict when encrypted_credentials is None."""
# Arrange
builtin_provider = BuiltinToolProvider(
@@ -144,7 +145,7 @@ class TestBuiltinToolProviderValidation:
# Assert
assert result == {}
- def test_builtin_tool_provider_credentials_empty_when_empty_string(self):
+ def test_builtin_tool_provider_credentials_empty_when_empty_string(self) -> None:
"""Test credentials property returns empty dict when encrypted_credentials is empty."""
# Arrange
builtin_provider = BuiltinToolProvider(
@@ -161,7 +162,7 @@ class TestBuiltinToolProviderValidation:
# Assert
assert result == {}
- def test_builtin_tool_provider_default_values(self):
+ def test_builtin_tool_provider_default_values(self) -> None:
"""Test builtin tool provider default values."""
# Arrange & Act
builtin_provider = BuiltinToolProvider(
@@ -176,7 +177,7 @@ class TestBuiltinToolProviderValidation:
assert builtin_provider.credential_type == "api-key"
assert builtin_provider.expires_at == -1
- def test_builtin_tool_provider_with_oauth_credential_type(self):
+ def test_builtin_tool_provider_with_oauth_credential_type(self) -> None:
"""Test builtin tool provider with OAuth credential type."""
# Arrange
credentials = {
@@ -192,7 +193,7 @@ class TestBuiltinToolProviderValidation:
provider="google",
name="Google OAuth",
encrypted_credentials=json.dumps(credentials),
- credential_type="oauth2",
+ credential_type=CredentialType.OAUTH2,
expires_at=1735689600,
)
@@ -201,7 +202,7 @@ class TestBuiltinToolProviderValidation:
assert builtin_provider.expires_at == 1735689600
assert builtin_provider.credentials["access_token"] == "oauth_token_123"
- def test_builtin_tool_provider_is_default_flag(self):
+ def test_builtin_tool_provider_is_default_flag(self) -> None:
"""Test is_default flag for builtin tool provider."""
# Arrange
provider1 = BuiltinToolProvider(
@@ -223,7 +224,7 @@ class TestBuiltinToolProviderValidation:
assert provider1.is_default is True
assert provider2.is_default is False
- def test_builtin_tool_provider_unique_constraint_fields(self):
+ def test_builtin_tool_provider_unique_constraint_fields(self) -> None:
"""Test unique constraint fields (tenant_id, provider, name)."""
# Arrange
tenant_id = str(uuid4())
@@ -243,7 +244,7 @@ class TestBuiltinToolProviderValidation:
assert builtin_provider.provider == provider_name
assert builtin_provider.name == credential_name
- def test_builtin_tool_provider_multiple_credentials_same_provider(self):
+ def test_builtin_tool_provider_multiple_credentials_same_provider(self) -> None:
"""Test multiple credential sets for the same provider."""
# Arrange
tenant_id = str(uuid4())
@@ -275,7 +276,7 @@ class TestBuiltinToolProviderValidation:
class TestApiToolProviderValidation:
"""Test suite for ApiToolProvider model validation and operations."""
- def test_api_tool_provider_creation_with_required_fields(self):
+ def test_api_tool_provider_creation_with_required_fields(self) -> None:
"""Test creating an API tool provider with all required fields."""
# Arrange
tenant_id = str(uuid4())
@@ -306,7 +307,7 @@ class TestApiToolProviderValidation:
assert api_provider.schema_type_str == ApiProviderSchemaType.OPENAPI
assert api_provider.description == "Custom API for testing"
- def test_api_tool_provider_schema_type_property(self):
+ def test_api_tool_provider_schema_type_property(self) -> None:
"""Test schema_type property converts string to enum."""
# Arrange
api_provider = ApiToolProvider(
@@ -327,10 +328,10 @@ class TestApiToolProviderValidation:
# Assert
assert result == ApiProviderSchemaType.OPENAPI
- def test_api_tool_provider_tools_property(self):
+ def test_api_tool_provider_tools_property(self) -> None:
"""Test tools property parses JSON and returns ApiToolBundle list."""
# Arrange
- tools_data = [
+ tools_data: list[dict[str, object]] = [
{
"author": "test",
"server_url": "https://api.weather.com",
@@ -382,7 +383,7 @@ class TestApiToolProviderValidation:
assert result[0].operation_id == "getWeather"
assert result[1].operation_id == "getLocation"
- def test_api_tool_provider_credentials_property(self):
+ def test_api_tool_provider_credentials_property(self) -> None:
"""Test credentials property parses JSON correctly."""
# Arrange
credentials_data = {
@@ -411,7 +412,7 @@ class TestApiToolProviderValidation:
assert result["api_key_header"] == "Authorization"
assert result["api_key_value"] == "Bearer test_token"
- def test_api_tool_provider_with_privacy_policy(self):
+ def test_api_tool_provider_with_privacy_policy(self) -> None:
"""Test API tool provider with privacy policy."""
# Arrange
privacy_policy_url = "https://example.com/privacy"
@@ -433,7 +434,7 @@ class TestApiToolProviderValidation:
# Assert
assert api_provider.privacy_policy == privacy_policy_url
- def test_api_tool_provider_with_custom_disclaimer(self):
+ def test_api_tool_provider_with_custom_disclaimer(self) -> None:
"""Test API tool provider with custom disclaimer."""
# Arrange
disclaimer = "This API is provided as-is without warranty."
@@ -455,7 +456,7 @@ class TestApiToolProviderValidation:
# Assert
assert api_provider.custom_disclaimer == disclaimer
- def test_api_tool_provider_default_custom_disclaimer(self):
+ def test_api_tool_provider_default_custom_disclaimer(self) -> None:
"""Test API tool provider default custom_disclaimer is empty string."""
# Arrange & Act
api_provider = ApiToolProvider(
@@ -473,7 +474,7 @@ class TestApiToolProviderValidation:
# Assert
assert api_provider.custom_disclaimer == ""
- def test_api_tool_provider_unique_constraint_fields(self):
+ def test_api_tool_provider_unique_constraint_fields(self) -> None:
"""Test unique constraint fields (name, tenant_id)."""
# Arrange
tenant_id = str(uuid4())
@@ -496,7 +497,7 @@ class TestApiToolProviderValidation:
assert api_provider.tenant_id == tenant_id
assert api_provider.name == provider_name
- def test_api_tool_provider_with_no_auth(self):
+ def test_api_tool_provider_with_no_auth(self) -> None:
"""Test API tool provider with no authentication."""
# Arrange
credentials = {"auth_type": "none"}
@@ -517,7 +518,7 @@ class TestApiToolProviderValidation:
# Assert
assert api_provider.credentials["auth_type"] == "none"
- def test_api_tool_provider_with_api_key_query_auth(self):
+ def test_api_tool_provider_with_api_key_query_auth(self) -> None:
"""Test API tool provider with API key in query parameter."""
# Arrange
credentials = {
@@ -547,7 +548,7 @@ class TestApiToolProviderValidation:
class TestToolOAuthModels:
"""Test suite for OAuth client models (system and tenant level)."""
- def test_oauth_system_client_creation(self):
+ def test_oauth_system_client_creation(self) -> None:
"""Test creating a system-level OAuth client."""
# Arrange
plugin_id = "builtin.google"
@@ -568,7 +569,7 @@ class TestToolOAuthModels:
assert oauth_client.provider == provider
assert oauth_client.encrypted_oauth_params == oauth_params
- def test_oauth_system_client_unique_constraint(self):
+ def test_oauth_system_client_unique_constraint(self) -> None:
"""Test unique constraint on plugin_id and provider."""
# Arrange
plugin_id = "builtin.github"
@@ -585,7 +586,7 @@ class TestToolOAuthModels:
assert oauth_client.plugin_id == plugin_id
assert oauth_client.provider == provider
- def test_oauth_tenant_client_creation(self):
+ def test_oauth_tenant_client_creation(self) -> None:
"""Test creating a tenant-level OAuth client."""
# Arrange
tenant_id = str(uuid4())
@@ -607,7 +608,7 @@ class TestToolOAuthModels:
assert oauth_client.plugin_id == plugin_id
assert oauth_client.provider == provider
- def test_oauth_tenant_client_enabled_default(self):
+ def test_oauth_tenant_client_enabled_default(self) -> None:
"""Test OAuth tenant client enabled flag has init=False and uses server default."""
# Arrange & Act
oauth_client = ToolOAuthTenantClient(
@@ -621,7 +622,7 @@ class TestToolOAuthModels:
oauth_client.enabled = True
assert oauth_client.enabled is True
- def test_oauth_tenant_client_oauth_params_property(self):
+ def test_oauth_tenant_client_oauth_params_property(self) -> None:
"""Test oauth_params property parses JSON correctly."""
# Arrange
params_data = {
@@ -645,7 +646,7 @@ class TestToolOAuthModels:
assert result["client_id"] == "test_client_123"
assert result["redirect_uri"] == "https://app.example.com/callback"
- def test_oauth_tenant_client_oauth_params_empty_when_none(self):
+ def test_oauth_tenant_client_oauth_params_empty_when_none(self) -> None:
"""Test oauth_params returns empty dict when encrypted_oauth_params is None."""
# Arrange
oauth_client = ToolOAuthTenantClient(
@@ -653,8 +654,7 @@ class TestToolOAuthModels:
plugin_id="builtin.test",
provider="test",
)
- # encrypted_oauth_params has init=False, set it to None
- oauth_client.encrypted_oauth_params = None
+ # encrypted_oauth_params has init=False, so a transient instance reads it as None
# Act
result = oauth_client.oauth_params
@@ -662,7 +662,7 @@ class TestToolOAuthModels:
# Assert
assert result == {}
- def test_oauth_tenant_client_disabled_state(self):
+ def test_oauth_tenant_client_disabled_state(self) -> None:
"""Test OAuth tenant client can be disabled."""
# Arrange
oauth_client = ToolOAuthTenantClient(
@@ -681,7 +681,7 @@ class TestToolOAuthModels:
class TestToolLabelBinding:
"""Test suite for ToolLabelBinding model."""
- def test_tool_label_binding_creation(self):
+ def test_tool_label_binding_creation(self) -> None:
"""Test creating a tool label binding."""
# Arrange
tool_id = "google.search"
@@ -700,7 +700,7 @@ class TestToolLabelBinding:
assert label_binding.tool_type == tool_type
assert label_binding.label_name == label_name
- def test_tool_label_binding_unique_constraint(self):
+ def test_tool_label_binding_unique_constraint(self) -> None:
"""Test unique constraint on tool_id and label_name."""
# Arrange
tool_id = "openai.text_generation"
@@ -717,7 +717,7 @@ class TestToolLabelBinding:
assert label_binding.tool_id == tool_id
assert label_binding.label_name == label_name
- def test_tool_label_binding_multiple_labels_same_tool(self):
+ def test_tool_label_binding_multiple_labels_same_tool(self) -> None:
"""Test multiple labels can be bound to the same tool."""
# Arrange
tool_id = "google.search"
@@ -739,7 +739,7 @@ class TestToolLabelBinding:
assert binding1.tool_id == binding2.tool_id
assert binding1.label_name != binding2.label_name
- def test_tool_label_binding_different_tool_types(self):
+ def test_tool_label_binding_different_tool_types(self) -> None:
"""Test label bindings for different tool types."""
# Arrange
tool_types = [ToolProviderType.BUILT_IN, ToolProviderType.API, ToolProviderType.WORKFLOW]
@@ -757,7 +757,7 @@ class TestToolLabelBinding:
class TestCredentialStorage:
"""Test suite for credential storage and encryption patterns."""
- def test_builtin_provider_credential_storage_format(self):
+ def test_builtin_provider_credential_storage_format(self) -> None:
"""Test builtin provider stores credentials as JSON string."""
# Arrange
credentials = {
@@ -779,7 +779,7 @@ class TestCredentialStorage:
assert isinstance(provider.encrypted_credentials, str)
assert provider.credentials == credentials
- def test_api_provider_credential_storage_format(self):
+ def test_api_provider_credential_storage_format(self) -> None:
"""Test API provider stores credentials as JSON string."""
# Arrange
credentials = {
@@ -805,7 +805,7 @@ class TestCredentialStorage:
assert isinstance(provider.credentials_str, str)
assert provider.credentials == credentials
- def test_builtin_provider_complex_credential_structure(self):
+ def test_builtin_provider_complex_credential_structure(self) -> None:
"""Test builtin provider with complex nested credential structure."""
# Arrange
credentials = {
@@ -832,7 +832,7 @@ class TestCredentialStorage:
assert provider.credentials["oauth_config"]["access_token"] == "token123"
assert provider.credentials["additional_headers"]["X-Custom-Header"] == "value"
- def test_api_provider_credential_update_pattern(self):
+ def test_api_provider_credential_update_pattern(self) -> None:
"""Test pattern for updating API provider credentials."""
# Arrange
original_credentials = {"auth_type": "api_key_header", "api_key_value": "old_key"}
@@ -855,7 +855,7 @@ class TestCredentialStorage:
# Assert
assert provider.credentials["api_key_value"] == "new_key"
- def test_builtin_provider_credential_expiration(self):
+ def test_builtin_provider_credential_expiration(self) -> None:
"""Test builtin provider credential expiration tracking."""
# Arrange
future_timestamp = 1735689600 # Future date
@@ -889,7 +889,7 @@ class TestCredentialStorage:
assert expired_provider.expires_at == past_timestamp
assert never_expires_provider.expires_at == -1
- def test_oauth_client_credential_storage(self):
+ def test_oauth_client_credential_storage(self) -> None:
"""Test OAuth client credential storage pattern."""
# Arrange
oauth_credentials = {
@@ -923,7 +923,7 @@ class TestCredentialStorage:
class TestToolProviderRelationships:
"""Test suite for tool provider relationships and associations."""
- def test_builtin_provider_tenant_relationship(self):
+ def test_builtin_provider_tenant_relationship(self) -> None:
"""Test builtin provider belongs to a tenant."""
# Arrange
tenant_id = str(uuid4())
@@ -939,7 +939,7 @@ class TestToolProviderRelationships:
# Assert
assert provider.tenant_id == tenant_id
- def test_api_provider_user_relationship(self):
+ def test_api_provider_user_relationship(self) -> None:
"""Test API provider belongs to a user."""
# Arrange
user_id = str(uuid4())
@@ -960,7 +960,7 @@ class TestToolProviderRelationships:
# Assert
assert provider.user_id == user_id
- def test_multiple_providers_same_tenant(self):
+ def test_multiple_providers_same_tenant(self) -> None:
"""Test multiple providers can belong to the same tenant."""
# Arrange
tenant_id = str(uuid4())
@@ -996,7 +996,7 @@ class TestToolProviderRelationships:
assert builtin2.tenant_id == tenant_id
assert api1.tenant_id == tenant_id
- def test_tool_label_bindings_for_provider_tools(self):
+ def test_tool_label_bindings_for_provider_tools(self) -> None:
"""Test tool label bindings can be associated with provider tools."""
# Arrange
provider_name = "google"
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.toml
index b1f30e11d7d..40adf412b8b 100644
--- a/api/tests/unit_tests/pyrefly.toml
+++ b/api/tests/unit_tests/pyrefly.toml
@@ -265,9 +265,7 @@ project-excludes = [
"libs/test_schedule_utils.py",
"libs/test_external_api.py",
"migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py",
- "models/test_account.py",
"models/test_model.py",
- "models/test_tools.py",
"services/agent/test_dsl_service.py",
"services/agent/test_roster_service.py",
"../helpers/unit/services/controller_api.py",