Tests fix
This commit is contained in:
parent
1f135d09ec
commit
ceb6fda4c6
5 changed files with 61 additions and 81 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
|
@ -20,7 +22,11 @@ def create_app(static_path: str = "static"):
|
|||
|
||||
@app.exception_handler(404)
|
||||
async def custom_404_handler(request, __):
|
||||
return FileResponse(f"{static_path}/index.html")
|
||||
path = f"{static_path}/index.html"
|
||||
|
||||
if not os.path.isfile(path):
|
||||
raise RuntimeError(f"File at path {path} does not exist.")
|
||||
return FileResponse(path)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ def test_initialize_agent(client: TestClient):
|
|||
json_response = response.json()
|
||||
agents = json_response["agents"]
|
||||
|
||||
initialize_agent = agents["initialize_agent"]
|
||||
initialize_agent = agents["AgentInitializer"]
|
||||
assert initialize_agent["base_classes"] == ["AgentExecutor", "function"]
|
||||
template = initialize_agent["template"]
|
||||
|
||||
|
|
@ -136,6 +136,7 @@ def test_initialize_agent(client: TestClient):
|
|||
"react-docstore",
|
||||
"self-ask-with-search",
|
||||
"conversational-react-description",
|
||||
"openai-functions",
|
||||
],
|
||||
"name": "agent",
|
||||
"type": "str",
|
||||
|
|
|
|||
|
|
@ -18,14 +18,15 @@ def test_conversation_chain(client: TestClient):
|
|||
chains = json_response["chains"]
|
||||
|
||||
chain = chains["ConversationChain"]
|
||||
|
||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
||||
assert set(chain["base_classes"]) == {
|
||||
"function",
|
||||
"LLMChain",
|
||||
"ConversationChain",
|
||||
"LLMChain",
|
||||
"Chain",
|
||||
"Serializable",
|
||||
"function",
|
||||
}
|
||||
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
|
|
@ -101,7 +102,13 @@ def test_llm_chain(client: TestClient):
|
|||
chain = chains["LLMChain"]
|
||||
|
||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
||||
assert set(chain["base_classes"]) == {"function", "LLMChain", "Chain"}
|
||||
assert set(chain["base_classes"]) == {
|
||||
"Serializable",
|
||||
"function",
|
||||
"LLMChain",
|
||||
"Chain"
|
||||
}
|
||||
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
|
|
@ -159,31 +166,14 @@ def test_llm_checker_chain(client: TestClient):
|
|||
chain = chains["LLMCheckerChain"]
|
||||
|
||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
||||
assert set(chain["base_classes"]) == {"function", "LLMCheckerChain", "Chain"}
|
||||
assert set(chain["base_classes"]) == {
|
||||
"Serializable",
|
||||
"function",
|
||||
"LLMCheckerChain",
|
||||
"Chain"
|
||||
}
|
||||
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": False,
|
||||
"password": False,
|
||||
"name": "verbose",
|
||||
"type": "bool",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["llm"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
|
|
@ -195,35 +185,11 @@ def test_llm_checker_chain(client: TestClient):
|
|||
"list": False,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "query",
|
||||
"password": False,
|
||||
"name": "input_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["output_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "result",
|
||||
"password": False,
|
||||
"name": "output_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["_type"] == "LLMCheckerChain"
|
||||
|
||||
# Test the description object
|
||||
assert (
|
||||
chain["description"] == "Chain for question-answering with self-verification."
|
||||
chain["description"] == ""
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -234,9 +200,14 @@ def test_llm_math_chain(client: TestClient):
|
|||
chains = json_response["chains"]
|
||||
|
||||
chain = chains["LLMMathChain"]
|
||||
|
||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
||||
assert set(chain["base_classes"]) == {"function", "LLMMathChain", "Chain"}
|
||||
assert set(chain["base_classes"]) == {
|
||||
"function",
|
||||
"Serializable",
|
||||
"LLMMathChain",
|
||||
"Chain"
|
||||
}
|
||||
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
|
|
@ -450,4 +421,4 @@ def test_time_travel_guide_chain(client: TestClient):
|
|||
"advanced": False,
|
||||
}
|
||||
|
||||
assert chain["description"] == "Time travel guide chain to be used in the flow."
|
||||
assert chain["description"] == "Time travel guide chain."
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
from uuid import UUID, uuid4
|
||||
from langflow.api.v1.schemas import FlowListCreate
|
||||
from langflow.database.models.flow import FlowCreate, FlowUpdate
|
||||
import json
|
||||
import pytest
|
||||
import threading
|
||||
|
||||
from uuid import UUID, uuid4
|
||||
from sqlalchemy.orm import Session
|
||||
from langflow.database.models.flow import Flow
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
|
||||
from langflow.api.v1.schemas import FlowListCreate
|
||||
from langflow.database.models.flow import Flow, FlowCreate, FlowUpdate
|
||||
|
||||
from langflow.database.models.flow_style import (
|
||||
FlowStyleCreate,
|
||||
FlowStyleRead,
|
||||
FlowStyleUpdate,
|
||||
)
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
|
||||
import pytest
|
||||
|
||||
import threading
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
@ -37,13 +37,13 @@ def test_create_flow(client: TestClient, json_flow: str):
|
|||
data = flow["data"]
|
||||
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||
response = client.post("api/v1/flows/", json=flow.dict())
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == flow.name
|
||||
assert response.json()["data"] == flow.data
|
||||
# flow is optional so we can create a flow without a flow
|
||||
flow = FlowCreate(name="Test Flow")
|
||||
response = client.post("api/v1/flows/", json=flow.dict(exclude_unset=True))
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == flow.name
|
||||
assert response.json()["data"] == flow.data
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ def test_read_flows(client: TestClient, json_flow: str):
|
|||
data = flow_data["data"]
|
||||
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||
response = client.post("api/v1/flows/", json=flow.dict())
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == flow.name
|
||||
assert response.json()["data"] == flow.data
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ def test_read_flows(client: TestClient, json_flow: str):
|
|||
|
||||
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||
response = client.post("api/v1/flows/", json=flow.dict())
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == flow.name
|
||||
assert response.json()["data"] == flow.data
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ def test_create_flows(client: TestClient, session: Session, json_flow: str):
|
|||
# Make request to endpoint
|
||||
response = client.post("api/v1/flows/batch/", json=flow_list.dict())
|
||||
# Check response status code
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
# Check response data
|
||||
response_data = response.json()
|
||||
assert len(response_data) == 2
|
||||
|
|
@ -185,7 +185,7 @@ def test_upload_file(client: TestClient, session: Session, json_flow: str):
|
|||
files={"file": ("examples.json", file_contents, "application/json")},
|
||||
)
|
||||
# Check response status code
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
# Check response data
|
||||
response_data = response.json()
|
||||
assert len(response_data) == 2
|
||||
|
|
@ -233,10 +233,10 @@ def test_create_flow_with_invalid_data(client: TestClient):
|
|||
|
||||
|
||||
def test_get_nonexistent_flow(client: TestClient):
|
||||
# uuid4 generates a random UUID
|
||||
uuid = uuid4()
|
||||
response = client.get(f"api/v1/flows/{uuid}")
|
||||
assert response.status_code == 404
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
client.get(f"api/v1/flows/{uuid}")
|
||||
assert str(excinfo.value) == "File at path static/index.html does not exist."
|
||||
|
||||
|
||||
def test_update_flow_idempotency(client: TestClient, json_flow: str):
|
||||
|
|
@ -260,14 +260,16 @@ def test_update_nonexistent_flow(client: TestClient, json_flow: str):
|
|||
description="description",
|
||||
data=data,
|
||||
)
|
||||
response = client.patch(f"api/v1/flows/{uuid}", json=updated_flow.dict())
|
||||
assert response.status_code == 404
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
client.patch(f"api/v1/flows/{uuid}", json=updated_flow.dict())
|
||||
assert str(excinfo.value) == "File at path static/index.html does not exist."
|
||||
|
||||
|
||||
def test_delete_nonexistent_flow(client: TestClient):
|
||||
uuid = uuid4()
|
||||
response = client.delete(f"api/v1/flows/{uuid}")
|
||||
assert response.status_code == 404
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
client.delete(f"api/v1/flows/{uuid}")
|
||||
assert str(excinfo.value) == "File at path static/index.html does not exist."
|
||||
|
||||
|
||||
def test_read_empty_flows(client: TestClient):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ def test_init_build(client):
|
|||
response = client.post(
|
||||
"api/v1/build/init", json={"id": "test", "data": {"key": "value"}}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.json() == {"flowId": "test"}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue