From a61b2bbe1dd468e5c029a9b53a6d58f945552136 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Sep 2023 11:55:39 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(conftest.py):=20import=20o?= =?UTF-8?q?rjson=20library=20for=20JSON=20handling=20=F0=9F=94=A7=20chore(?= =?UTF-8?q?conftest.py):=20add=20pytest=20fixture=20for=20loading=20JSON?= =?UTF-8?q?=20flow=20with=20prompt=20and=20history=20=F0=9F=94=A7=20chore(?= =?UTF-8?q?conftest.py):=20add=20pytest=20fixture=20for=20adding=20a=20flo?= =?UTF-8?q?w=20with=20prompt=20and=20history=20to=20the=20database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/conftest.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1d1fb9ac7..8df9e1655 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,9 @@ from langflow.api.v1.flows import get_session from langflow.graph.graph.base import Graph from langflow.services.auth.utils import get_password_hash -from langflow.services.database.models.flow.flow import Flow +from langflow.services.database.models.flow.flow import Flow, FlowCreate from langflow.services.database.models.user.user import User, UserCreate +import orjson import pytest from fastapi.testclient import TestClient from httpx import AsyncClient @@ -29,6 +30,9 @@ def pytest_configure(): pytest.OPENAPI_EXAMPLE_PATH = ( Path(__file__).parent.absolute() / "data" / "Openapi.json" ) + pytest.BASIC_CHAT_WITH_PROMPT_AND_HISTORY = ( + Path(__file__).parent.absolute() / "data" / "BasicChatWithPromptAndHistory.json" + ) pytest.CODE_WITH_SYNTAX_ERROR = """ def get_text(): @@ -101,6 +105,12 @@ def json_flow(): return f.read() +@pytest.fixture +def json_flow_with_prompt_and_history(): + with open(pytest.BASIC_CHAT_WITH_PROMPT_AND_HISTORY, "r") as f: + return f.read() + + @pytest.fixture(name="session") def session_fixture(): engine = create_engine( @@ -208,3 +218,15 @@ def flow(client, json_flow: str, session, active_user): session.commit() return flow + + +@pytest.fixture +def added_flow(client, json_flow_with_prompt_and_history, logged_in_headers): + flow = orjson.loads(json_flow_with_prompt_and_history) + data = flow["data"] + flow = FlowCreate(name="Basic Chat", description="description", data=data) + response = client.post("api/v1/flows/", json=flow.dict(), headers=logged_in_headers) + assert response.status_code == 201 + assert response.json()["name"] == flow.name + assert response.json()["data"] == flow.data + return response.json()