From 00290d0f9ef5317d10d0817f81920fb5bd9fce85 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Sep 2023 14:49:20 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(test=5Fendpoints.py):=20remo?= =?UTF-8?q?ve=20unused=20imports=20and=20refactor=20test=5Fbasic=5Fchat=5F?= =?UTF-8?q?with=5Ftwo=5Fsession=5Fids=5Fand=5Fnames=20to=20use=20a=20loop?= =?UTF-8?q?=20for=20better=20readability=20and=20maintainability=20?= =?UTF-8?q?=E2=9C=A8=20feat(test=5Fendpoints.py):=20add=20test=5Fbasic=5Fc?= =?UTF-8?q?hat=5Fwith=5Ftwo=5Fsession=5Fids=5Fand=5Fnames=20to=20test=20th?= =?UTF-8?q?e=20functionality=20of=20handling=20multiple=20session=20IDs=20?= =?UTF-8?q?and=20names=20in=20the=20chat=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_endpoints.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 29c5d5a91..fac7adb34 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -8,6 +8,8 @@ from fastapi.testclient import TestClient from langflow.interface.tools.constants import CUSTOM_TOOLS from langflow.template.frontend_node.chains import TimeTravelGuideChainNode +from tests.utils import run_post + PROMPT_REQUEST = { "name": "string", @@ -422,30 +424,27 @@ def test_basic_chat_different_session_ids(client, added_flow, created_api_key): assert "Gabriel" not in response.json()["result"]["text"] -@pytest.mark.parametrize("name", ["Gabriel", "John"]) -def test_basic_chat_with_two_session_ids_and_names( - client, added_flow, created_api_key, name -): +def test_basic_chat_with_two_session_ids_and_names(client, added_flow, created_api_key): headers = {"x-api-key": created_api_key.api_key} + flow_id = added_flow.get("id") + names = ["Gabriel", "John"] + session_ids = [] - def run_api_post(endpoint, headers, post_data): - response = client.post(endpoint, headers=headers, json=post_data) - assert response.status_code == 200, response.json() - return response.json() + for name in names: + post_data = {"inputs": {"text": f"Hi, My name is {name}"}} + response_json = run_post(client, flow_id, headers, post_data) - def assert_name_and_session_in_response(name, response_json): assert name in response_json["result"]["text"] assert "session_id" in response_json assert response_json["session_id"] is not None - # Run the /api/v1/process/{flow_id} endpoint - flow_id = added_flow.get("id") - post_data = {"inputs": {"text": f"Hi, My name is {name}"}} - response_json = run_api_post(f"api/v1/process/{flow_id}", headers, post_data) - assert_name_and_session_in_response(name, response_json) - session_id = response_json["session_id"] + session_ids.append(response_json["session_id"]) - # New request with the same session_id asking "What is my name?" should return name - post_data = {"inputs": {"text": "What is my name?"}, "session_id": session_id} - response_json = run_api_post(f"api/v1/process/{flow_id}", headers, post_data) - assert name in response_json["result"]["text"] + for i, name in enumerate(names): + post_data = { + "inputs": {"text": "What is my name?"}, + "session_id": session_ids[i], + } + response_json = run_post(client, flow_id, headers, post_data) + + assert name in response_json["result"]["text"]