File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
sample-applications/chat-question-and-answer/tests/unit_tests Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 11import pytest
2+ import sys
3+ from types import ModuleType
24from fastapi .testclient import TestClient
35
6+ chain_stub = ModuleType ("app.chain" )
7+ chain_stub .process_chunks = lambda * _args , ** _kwargs : iter ([])
8+ sys .modules ["app.chain" ] = chain_stub
9+
410# application packages
511from app .server import app
612
Original file line number Diff line number Diff line change 11def test_query_chain_successful_response (test_client , mocker ):
2- payload = {"input" : "What is AI?" }
2+ payload = {
3+ "conversation_messages" : [
4+ {"role" : "user" , "content" : "What is AI?" }
5+ ],
6+ "max_tokens" : 512 ,
7+ }
38 mocker .patch ("app.server.process_chunks" , return_value = iter (["one" , "two" ]))
49 response = test_client .post ("/chat" , json = payload )
510 assert response .status_code == 200
1318 assert "two" in streamed_data
1419
1520def test_query_chain_no_input (test_client ):
16- payload = {"input" : "" }
21+ payload = {
22+ "conversation_messages" : [
23+ {"role" : "user" , "content" : "" }
24+ ],
25+ "max_tokens" : 512 ,
26+ }
1727 response = test_client .post ("/chat" , json = payload )
1828 assert response .status_code == 422
1929 assert response .json () == {"detail" : "Question is required" }
You can’t perform that action at this time.
0 commit comments