mirror of
https://github.com/langgenius/dify.git
synced 2026-11-10 21:35:45 +08:00
test: use unbound_session in openapi streaming run test (#44999)
Signed-off-by: Vitalii <2556969@gmail.com>
This commit is contained in:
1 parent
4eef080524
commit
fefd2eb7b7
1 file changed
+8
-5
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user