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: use concrete agent account boundaries (#43371)

Asuka Minato4214abf28fb0
diff --git a/api/tests/unit_tests/clients/agent_backend/test_factory.py b/api/tests/unit_tests/clients/agent_backend/test_factory.py
index 4d0ae631a89..f289b73e013 100644
--- a/api/tests/unit_tests/clients/agent_backend/test_factory.py
+++ b/api/tests/unit_tests/clients/agent_backend/test_factory.py
@@ -85,13 +85,19 @@ def test_default_agent_backend_clients_forward_authentication(
AGENT_BACKEND_API_TOKEN="secret-token",
AGENT_BACKEND_BINDING_FILE_DOWNLOAD_TIMEOUT_SECONDS=123.5,
)
- create_client = MagicMock()
- monkeypatch.setattr(module, "create_agent_backend_client", create_client)
+ client_calls: list[dict[str, object]] = []
+
+ def record_client_call(**kwargs: object) -> None:
+ client_calls.append(kwargs)
+
+ monkeypatch.setattr(module, "create_agent_backend_client", record_client_call)
factory()
- create_client.assert_called_once_with(
- base_url="http://agent-backend",
- api_token="secret-token",
- **extra_kwargs,
- )
+ assert client_calls == [
+ {
+ "base_url": "http://agent-backend",
+ "api_token": "secret-token",
+ **extra_kwargs,
+ }
+ ]
diff --git a/api/tests/unit_tests/commands/test_account_commands.py b/api/tests/unit_tests/commands/test_account_commands.py
index cdfb7bd9567..951f3533b92 100644
--- a/api/tests/unit_tests/commands/test_account_commands.py
+++ b/api/tests/unit_tests/commands/test_account_commands.py
@@ -1,17 +1,25 @@
-from unittest.mock import Mock
-
import pytest
from click.testing import CliRunner
+from sqlalchemy.orm import Session
from commands.account import reset_email, reset_password
+from extensions.ext_application_services import ApplicationServices
+from models.account import Account
-def test_reset_password_does_not_swallow_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
- monkeypatch.setattr(
- "commands.account.application_services",
- Mock(return_value=Mock()),
- )
- monkeypatch.setattr("commands.account.valid_password", Mock(side_effect=KeyboardInterrupt))
+def _raise_keyboard_interrupt(*_args: object, **_kwargs: object) -> None:
+ raise KeyboardInterrupt
+
+
+def test_reset_password_does_not_swallow_keyboard_interrupt(
+ monkeypatch: pytest.MonkeyPatch,
+ sqlite_session: Session,
+ account_application_services: ApplicationServices,
+) -> None:
+ sqlite_session.add(Account(name="Command User", email="[email protected]"))
+ sqlite_session.commit()
+ monkeypatch.setattr("commands.account.application_services", lambda: account_application_services)
+ monkeypatch.setattr("commands.account.valid_password", _raise_keyboard_interrupt)
result = CliRunner().invoke(
reset_password,
@@ -22,12 +30,15 @@ def test_reset_password_does_not_swallow_keyboard_interrupt(monkeypatch: pytest.
assert "Invalid password" not in result.output
-def test_reset_email_does_not_swallow_keyboard_interrupt(monkeypatch: pytest.MonkeyPatch) -> None:
- monkeypatch.setattr(
- "commands.account.application_services",
- Mock(return_value=Mock()),
- )
- monkeypatch.setattr("commands.account.email_validate", Mock(side_effect=KeyboardInterrupt))
+def test_reset_email_does_not_swallow_keyboard_interrupt(
+ monkeypatch: pytest.MonkeyPatch,
+ sqlite_session: Session,
+ account_application_services: ApplicationServices,
+) -> None:
+ sqlite_session.add(Account(name="Command User", email="[email protected]"))
+ sqlite_session.commit()
+ monkeypatch.setattr("commands.account.application_services", lambda: account_application_services)
+ monkeypatch.setattr("commands.account.email_validate", _raise_keyboard_interrupt)
result = CliRunner().invoke(
reset_email,