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 unbound_session in openapi streaming run test (#44999)

Vitalii Borovykfefd2eb7b7ba
diff --git a/api/tests/unit_tests/controllers/openapi/test_app_run.py b/api/tests/unit_tests/controllers/openapi/test_app_run.py
index 7d3dcf069bb..54a7523b680 100644
--- a/api/tests/unit_tests/controllers/openapi/test_app_run.py
+++ b/api/tests/unit_tests/controllers/openapi/test_app_run.py
@@ -230,7 +230,7 @@ def _generate_stub(monkeypatch: pytest.MonkeyPatch, chunks: list[str]) -> Mock:
return generate_mock
-def _ctx(mode: AppMode, session: Session | Mock | None = None) -> _SealableContext:
+def _ctx(mode: AppMode, session: Session | None = None) -> _SealableContext:
app_model = _make_app()
app_model.mode = mode
return _SealableContext(
@@ -241,10 +241,13 @@ def _ctx(mode: AppMode, session: Session | Mock | None = None) -> _SealableConte
)
-def test_run_reads_everything_off_the_context_before_streaming(app: Flask, monkeypatch: pytest.MonkeyPatch):
+def test_run_reads_everything_off_the_context_before_streaming(
+ app: Flask, monkeypatch: pytest.MonkeyPatch, unbound_session: Session
+) -> None:
generate_mock = _generate_stub(monkeypatch, ["event: a\n\n", "event: b\n\n"])
- session = Mock()
- ctx = _ctx(AppMode.ADVANCED_CHAT, session)
+ commits: list[Session] = []
+ event.listen(unbound_session, "after_commit", commits.append)
+ ctx = _ctx(AppMode.ADVANCED_CHAT, unbound_session)
api = AdvancedChatRunApi()
body = AdvancedChatRunPayload(inputs={}, query="hi")
with app.test_request_context(f"/openapi/v1/apps/{_TEST_APP_ID}/advanced-chat:run", method="POST"):
@@ -254,7 +257,7 @@ def test_run_reads_everything_off_the_context_before_streaming(app: Flask, monke
assert body == "event: a\n\nevent: b\n\n"
assert generate_mock.call_args.kwargs["streaming"] is True
- session.commit.assert_not_called()
+ assert commits == []
def test_per_mode_route_refuses_an_app_of_another_mode(app: Flask, monkeypatch: pytest.MonkeyPatch):