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: migrate message extra contents tests to testcontainers (#32532)

木之本澪59681ce760e4
diff --git a/api/tests/test_containers_integration_tests/services/test_message_service_extra_contents.py b/api/tests/test_containers_integration_tests/services/test_message_service_extra_contents.py
new file mode 100644
index 00000000000..772365ba540
--- /dev/null
+++ b/api/tests/test_containers_integration_tests/services/test_message_service_extra_contents.py
@@ -0,0 +1,63 @@
+from __future__ import annotations
+
+from decimal import Decimal
+
+import pytest
+
+from models.model import Message
+from services import message_service
+from tests.test_containers_integration_tests.helpers.execution_extra_content import (
+ create_human_input_message_fixture,
+)
+
+
[email protected]("flask_req_ctx_with_containers")
+def test_attach_message_extra_contents_assigns_serialized_payload(db_session_with_containers) -> None:
+ fixture = create_human_input_message_fixture(db_session_with_containers)
+
+ message_without_extra_content = Message(
+ app_id=fixture.app.id,
+ model_provider=None,
+ model_id="",
+ override_model_configs=None,
+ conversation_id=fixture.conversation.id,
+ inputs={},
+ query="Query without extra content",
+ message={"messages": [{"role": "user", "content": "Query without extra content"}]},
+ message_tokens=0,
+ message_unit_price=Decimal(0),
+ message_price_unit=Decimal("0.001"),
+ answer="Answer without extra content",
+ answer_tokens=0,
+ answer_unit_price=Decimal(0),
+ answer_price_unit=Decimal("0.001"),
+ parent_message_id=None,
+ provider_response_latency=0,
+ total_price=Decimal(0),
+ currency="USD",
+ status="normal",
+ from_source="console",
+ from_account_id=fixture.account.id,
+ )
+ db_session_with_containers.add(message_without_extra_content)
+ db_session_with_containers.commit()
+
+ messages = [fixture.message, message_without_extra_content]
+
+ message_service.attach_message_extra_contents(messages)
+
+ assert messages[0].extra_contents == [
+ {
+ "type": "human_input",
+ "workflow_run_id": fixture.message.workflow_run_id,
+ "submitted": True,
+ "form_submission_data": {
+ "node_id": fixture.form.node_id,
+ "node_title": fixture.node_title,
+ "rendered_content": fixture.form.rendered_content,
+ "action_id": fixture.action_id,
+ "action_text": fixture.action_text,
+ },
+ }
+ ]
+ assert messages[1].extra_contents == []
diff --git a/api/tests/unit_tests/services/test_message_service_extra_contents.py b/api/tests/unit_tests/services/test_message_service_extra_contents.py
deleted file mode 100644
index 3c8e301caaf..00000000000
--- a/api/tests/unit_tests/services/test_message_service_extra_contents.py
+++ /dev/null
@@ -1,61 +0,0 @@
-from __future__ import annotations
-
-import pytest
-
-from core.entities.execution_extra_content import HumanInputContent, HumanInputFormSubmissionData
-from services import message_service
-
-
-class _FakeMessage:
- def __init__(self, message_id: str):
- self.id = message_id
- self.extra_contents = None
-
- def set_extra_contents(self, contents):
- self.extra_contents = contents
-
-
-def test_attach_message_extra_contents_assigns_serialized_payload(monkeypatch: pytest.MonkeyPatch) -> None:
- messages = [_FakeMessage("msg-1"), _FakeMessage("msg-2")]
- repo = type(
- "Repo",
- (),
- {
- "get_by_message_ids": lambda _self, message_ids: [
- [
- HumanInputContent(
- workflow_run_id="workflow-run-1",
- submitted=True,
- form_submission_data=HumanInputFormSubmissionData(
- node_id="node-1",
- node_title="Approval",
- rendered_content="Rendered",
- action_id="approve",
- action_text="Approve",
- ),
- )
- ],
- [],
- ]
- },
- )()
-
- monkeypatch.setattr(message_service, "_create_execution_extra_content_repository", lambda: repo)
-
- message_service.attach_message_extra_contents(messages)
-
- assert messages[0].extra_contents == [
- {
- "type": "human_input",
- "workflow_run_id": "workflow-run-1",
- "submitted": True,
- "form_submission_data": {
- "node_id": "node-1",
- "node_title": "Approval",
- "rendered_content": "Rendered",
- "action_id": "approve",
- "action_text": "Approve",
- },
- }
- ]
- assert messages[1].extra_contents == []