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): use the str enums instead of raw strings in three test modules (#45102)

Felix Shia281afe383b2
diff --git a/api/tests/unit_tests/controllers/console/explore/test_completion.py b/api/tests/unit_tests/controllers/console/explore/test_completion.py
index e842be4ac0c..57683b59354 100644
--- a/api/tests/unit_tests/controllers/console/explore/test_completion.py
+++ b/api/tests/unit_tests/controllers/console/explore/test_completion.py
@@ -12,6 +12,7 @@ import services.installed_app_generation_service as completion_service_module
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
from graphon.model_runtime.errors.invoke import InvokeError
from models import App, AppMode, Conversation, InstalledApp, Tenant
+from models.enums import ConversationFromSource
from repositories.installed_app_repository import SQLAlchemyInstalledAppRepository
from services.account_errors import AccountNotFoundError
from services.app_generate_service import AppGenerateService
@@ -815,7 +816,9 @@ class TestCompletionCases:
id=conversation_id,
app_id=str(uuid4()) if rejection == "other_app" else harness.target_app.id,
from_account_id=str(uuid4()) if rejection == "other_account" else harness.account.id,
- from_source="api" if rejection == "api" else "console",
+ from_source=ConversationFromSource.API
+ if rejection == "api"
+ else ConversationFromSource.CONSOLE,
mode=AppMode.CHAT,
name="Existing conversation",
_inputs={},
diff --git a/api/tests/unit_tests/core/app/apps/agent_app/test_session_store.py b/api/tests/unit_tests/core/app/apps/agent_app/test_session_store.py
index 85d08277497..47c978263e9 100644
--- a/api/tests/unit_tests/core/app/apps/agent_app/test_session_store.py
+++ b/api/tests/unit_tests/core/app/apps/agent_app/test_session_store.py
@@ -10,6 +10,7 @@ from models.agent import (
AgentWorkspaceBinding,
AgentWorkspaceOwnerType,
)
+from models.enums import ConversationFromSource
from models.model import App, AppMode, Conversation
from services.agent.workspace_service import AgentWorkspaceNotFoundError, AgentWorkspaceService
@@ -81,7 +82,7 @@ def _persist_conversation(session: Session, *, binding_id: str | None = None) ->
introduction="",
system_instruction="",
invoke_from=None,
- from_source="api",
+ from_source=ConversationFromSource.API,
from_end_user_id="user-1",
from_account_id=None,
read_at=None,
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.toml
index dac3efdcd7b..12414684232 100644
--- a/api/tests/unit_tests/pyrefly.toml
+++ b/api/tests/unit_tests/pyrefly.toml
@@ -50,7 +50,6 @@ project-excludes = [
"controllers/console/datasets/test_hit_testing.py",
"controllers/console/datasets/test_hit_testing_base.py",
"controllers/console/datasets/test_metadata.py",
- "controllers/console/explore/test_completion.py",
"controllers/console/snippets/test_snippet_workflow.py",
"controllers/console/snippets/test_snippet_workflow_draft_variable.py",
"controllers/console/tag/test_tags.py",
@@ -124,7 +123,6 @@ project-excludes = [
"core/app/apps/agent_app/test_app_generator.py",
"core/app/apps/agent_app/test_app_runner.py",
"core/app/apps/agent_app/test_runtime_request_builder.py",
- "core/app/apps/agent_app/test_session_store.py",
"core/app/apps/agent_chat/test_app_config_manager.py",
"core/app/apps/agent_chat/test_generate_response_converter.py",
"core/app/apps/chat/test_app_config_manager.py",
@@ -388,7 +386,6 @@ project-excludes = [
"services/test_billing_service.py",
"services/test_clear_free_plan_tenant_expired_logs.py",
"services/test_conversation_service.py",
- "services/test_credit_pool_service.py",
"services/knowledge/test_dataset_service.py",
"services/data_source/test_provider_service.py",
"services/knowledge/external/test_service.py",
diff --git a/api/tests/unit_tests/services/test_credit_pool_service.py b/api/tests/unit_tests/services/test_credit_pool_service.py
index 92bb8b5a244..2d2bb4bda53 100644
--- a/api/tests/unit_tests/services/test_credit_pool_service.py
+++ b/api/tests/unit_tests/services/test_credit_pool_service.py
@@ -574,7 +574,7 @@ def test_deduct_credits_capped_uses_billing_consume_capped_when_enabled(
],
)
def test_non_positive_credit_request_skips_tenant_redis_lock(
- deduct_method,
+ deduct_method: Callable[..., int],
sqlite_session: Session,
) -> None:
with patch("services.credit_pool_service.redis_client.lock") as lock: