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 conversation read timestamp SQL test to Testcontainers (#32454) (#35177)

bohdansolovie381c518b23e0
diff --git a/api/tests/test_containers_integration_tests/controllers/console/app/test_conversation_read_timestamp.py b/api/tests/test_containers_integration_tests/controllers/console/app/test_conversation_read_timestamp.py
new file mode 100644
index 00000000000..fad0b8b10e2
--- /dev/null
+++ b/api/tests/test_containers_integration_tests/controllers/console/app/test_conversation_read_timestamp.py
@@ -0,0 +1,73 @@
+from datetime import datetime
+from unittest.mock import patch
+
+import pytest
+from sqlalchemy.orm import Session
+from werkzeug.exceptions import NotFound
+
+from controllers.console.app.conversation import _get_conversation
+from models.enums import ConversationFromSource
+from models.model import AppMode, Conversation
+from tests.test_containers_integration_tests.controllers.console.helpers import (
+ create_console_account_and_tenant,
+ create_console_app,
+)
+
+
+def test_get_conversation_mark_read_keeps_updated_at_unchanged(
+ db_session_with_containers: Session,
+):
+ account, tenant = create_console_account_and_tenant(db_session_with_containers)
+ app = create_console_app(db_session_with_containers, tenant.id, account.id, AppMode.CHAT)
+
+ original_updated_at = datetime(2026, 2, 8, 0, 0, 0)
+ conversation = Conversation(
+ app_id=app.id,
+ name="read timestamp test",
+ inputs={},
+ status="normal",
+ mode=AppMode.CHAT,
+ from_source=ConversationFromSource.CONSOLE,
+ from_account_id=account.id,
+ updated_at=original_updated_at,
+ )
+ db_session_with_containers.add(conversation)
+ db_session_with_containers.commit()
+
+ read_at = datetime(2026, 2, 9, 0, 0, 0)
+
+ with (
+ patch(
+ "controllers.console.app.conversation.current_account_with_tenant",
+ return_value=(account, tenant.id),
+ autospec=True,
+ ),
+ patch(
+ "controllers.console.app.conversation.naive_utc_now",
+ return_value=read_at,
+ autospec=True,
+ ),
+ ):
+ loaded = _get_conversation(app, conversation.id)
+
+ db_session_with_containers.refresh(conversation)
+
+ assert loaded.id == conversation.id
+ assert conversation.read_at == read_at
+ assert conversation.read_account_id == account.id
+ assert conversation.updated_at == original_updated_at
+
+
+def test_get_conversation_raises_not_found_for_missing_conversation(
+ db_session_with_containers: Session,
+):
+ account, tenant = create_console_account_and_tenant(db_session_with_containers)
+ app = create_console_app(db_session_with_containers, tenant.id, account.id, AppMode.CHAT)
+
+ with patch(
+ "controllers.console.app.conversation.current_account_with_tenant",
+ return_value=(account, tenant.id),
+ autospec=True,
+ ):
+ with pytest.raises(NotFound):
+ _get_conversation(app, "00000000-0000-0000-0000-000000000000")
diff --git a/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py b/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py
deleted file mode 100644
index f588ab261d8..00000000000
--- a/api/tests/unit_tests/controllers/console/app/test_conversation_read_timestamp.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from datetime import datetime
-from types import SimpleNamespace
-from unittest.mock import MagicMock, patch
-
-from controllers.console.app.conversation import _get_conversation
-
-
-def test_get_conversation_mark_read_keeps_updated_at_unchanged():
- app_model = SimpleNamespace(id="app-id")
- account = SimpleNamespace(id="account-id")
- conversation = MagicMock()
- conversation.id = "conversation-id"
-
- with (
- patch(
- "controllers.console.app.conversation.current_account_with_tenant",
- return_value=(account, None),
- autospec=True,
- ),
- patch(
- "controllers.console.app.conversation.naive_utc_now",
- return_value=datetime(2026, 2, 9, 0, 0, 0),
- autospec=True,
- ),
- patch("controllers.console.app.conversation.db.session", autospec=True) as mock_session,
- ):
- mock_session.scalar.return_value = conversation
-
- _get_conversation(app_model, "conversation-id")
-
- statement = mock_session.execute.call_args[0][0]
- compiled = statement.compile()
- sql_text = str(compiled).lower()
- compact_sql_text = sql_text.replace(" ", "")
- params = compiled.params
-
- assert "updated_at=current_timestamp" not in compact_sql_text
- assert "updated_at=conversations.updated_at" in compact_sql_text
- assert "read_at=:read_at" in compact_sql_text
- assert "read_account_id=:read_account_id" in compact_sql_text
- assert params["read_at"] == datetime(2026, 2, 9, 0, 0, 0)
- assert params["read_account_id"] == "account-id"