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 import FastAPI
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
@ -20,7 +22,11 @@ def create_app(static_path: str = "static"):
|
||||||
|
|
||||||
@app.exception_handler(404)
|
@app.exception_handler(404)
|
||||||
async def custom_404_handler(request, __):
|
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(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ def test_initialize_agent(client: TestClient):
|
||||||
json_response = response.json()
|
json_response = response.json()
|
||||||
agents = json_response["agents"]
|
agents = json_response["agents"]
|
||||||
|
|
||||||
initialize_agent = agents["initialize_agent"]
|
initialize_agent = agents["AgentInitializer"]
|
||||||
assert initialize_agent["base_classes"] == ["AgentExecutor", "function"]
|
assert initialize_agent["base_classes"] == ["AgentExecutor", "function"]
|
||||||
template = initialize_agent["template"]
|
template = initialize_agent["template"]
|
||||||
|
|
||||||
|
|
@ -136,6 +136,7 @@ def test_initialize_agent(client: TestClient):
|
||||||
"react-docstore",
|
"react-docstore",
|
||||||
"self-ask-with-search",
|
"self-ask-with-search",
|
||||||
"conversational-react-description",
|
"conversational-react-description",
|
||||||
|
"openai-functions",
|
||||||
],
|
],
|
||||||
"name": "agent",
|
"name": "agent",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,15 @@ def test_conversation_chain(client: TestClient):
|
||||||
chains = json_response["chains"]
|
chains = json_response["chains"]
|
||||||
|
|
||||||
chain = chains["ConversationChain"]
|
chain = chains["ConversationChain"]
|
||||||
|
|
||||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
||||||
assert set(chain["base_classes"]) == {
|
assert set(chain["base_classes"]) == {
|
||||||
"function",
|
|
||||||
"LLMChain",
|
|
||||||
"ConversationChain",
|
"ConversationChain",
|
||||||
|
"LLMChain",
|
||||||
"Chain",
|
"Chain",
|
||||||
|
"Serializable",
|
||||||
|
"function",
|
||||||
}
|
}
|
||||||
|
|
||||||
template = chain["template"]
|
template = chain["template"]
|
||||||
assert template["memory"] == {
|
assert template["memory"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
|
|
@ -101,7 +102,13 @@ def test_llm_chain(client: TestClient):
|
||||||
chain = chains["LLMChain"]
|
chain = chains["LLMChain"]
|
||||||
|
|
||||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
# 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"]
|
template = chain["template"]
|
||||||
assert template["memory"] == {
|
assert template["memory"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
|
|
@ -159,31 +166,14 @@ def test_llm_checker_chain(client: TestClient):
|
||||||
chain = chains["LLMCheckerChain"]
|
chain = chains["LLMCheckerChain"]
|
||||||
|
|
||||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
# 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"]
|
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"] == {
|
assert template["llm"] == {
|
||||||
"required": True,
|
"required": True,
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
|
|
@ -195,35 +185,11 @@ def test_llm_checker_chain(client: TestClient):
|
||||||
"list": False,
|
"list": False,
|
||||||
"advanced": 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"
|
assert template["_type"] == "LLMCheckerChain"
|
||||||
|
|
||||||
# Test the description object
|
# Test the description object
|
||||||
assert (
|
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"]
|
chains = json_response["chains"]
|
||||||
|
|
||||||
chain = chains["LLMMathChain"]
|
chain = chains["LLMMathChain"]
|
||||||
|
|
||||||
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
# 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"]
|
template = chain["template"]
|
||||||
assert template["memory"] == {
|
assert template["memory"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
|
|
@ -450,4 +421,4 @@ def test_time_travel_guide_chain(client: TestClient):
|
||||||
"advanced": False,
|
"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 json
|
||||||
|
import pytest
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from uuid import UUID, uuid4
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from langflow.database.models.flow import Flow
|
|
||||||
from fastapi.testclient import TestClient
|
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 (
|
from langflow.database.models.flow_style import (
|
||||||
FlowStyleCreate,
|
FlowStyleCreate,
|
||||||
FlowStyleRead,
|
FlowStyleRead,
|
||||||
FlowStyleUpdate,
|
FlowStyleUpdate,
|
||||||
)
|
)
|
||||||
from fastapi.encoders import jsonable_encoder
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
|
|
@ -37,13 +37,13 @@ def test_create_flow(client: TestClient, json_flow: str):
|
||||||
data = flow["data"]
|
data = flow["data"]
|
||||||
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||||
response = client.post("api/v1/flows/", json=flow.dict())
|
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()["name"] == flow.name
|
||||||
assert response.json()["data"] == flow.data
|
assert response.json()["data"] == flow.data
|
||||||
# flow is optional so we can create a flow without a flow
|
# flow is optional so we can create a flow without a flow
|
||||||
flow = FlowCreate(name="Test Flow")
|
flow = FlowCreate(name="Test Flow")
|
||||||
response = client.post("api/v1/flows/", json=flow.dict(exclude_unset=True))
|
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()["name"] == flow.name
|
||||||
assert response.json()["data"] == flow.data
|
assert response.json()["data"] == flow.data
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ def test_read_flows(client: TestClient, json_flow: str):
|
||||||
data = flow_data["data"]
|
data = flow_data["data"]
|
||||||
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||||
response = client.post("api/v1/flows/", json=flow.dict())
|
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()["name"] == flow.name
|
||||||
assert response.json()["data"] == flow.data
|
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)
|
flow = FlowCreate(name="Test Flow", description="description", data=data)
|
||||||
response = client.post("api/v1/flows/", json=flow.dict())
|
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()["name"] == flow.name
|
||||||
assert response.json()["data"] == flow.data
|
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
|
# Make request to endpoint
|
||||||
response = client.post("api/v1/flows/batch/", json=flow_list.dict())
|
response = client.post("api/v1/flows/batch/", json=flow_list.dict())
|
||||||
# Check response status code
|
# Check response status code
|
||||||
assert response.status_code == 200
|
assert response.status_code == 201
|
||||||
# Check response data
|
# Check response data
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
assert len(response_data) == 2
|
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")},
|
files={"file": ("examples.json", file_contents, "application/json")},
|
||||||
)
|
)
|
||||||
# Check response status code
|
# Check response status code
|
||||||
assert response.status_code == 200
|
assert response.status_code == 201
|
||||||
# Check response data
|
# Check response data
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
assert len(response_data) == 2
|
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):
|
def test_get_nonexistent_flow(client: TestClient):
|
||||||
# uuid4 generates a random UUID
|
|
||||||
uuid = uuid4()
|
uuid = uuid4()
|
||||||
response = client.get(f"api/v1/flows/{uuid}")
|
with pytest.raises(RuntimeError) as excinfo:
|
||||||
assert response.status_code == 404
|
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):
|
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",
|
description="description",
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
response = client.patch(f"api/v1/flows/{uuid}", json=updated_flow.dict())
|
with pytest.raises(RuntimeError) as excinfo:
|
||||||
assert response.status_code == 404
|
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):
|
def test_delete_nonexistent_flow(client: TestClient):
|
||||||
uuid = uuid4()
|
uuid = uuid4()
|
||||||
response = client.delete(f"api/v1/flows/{uuid}")
|
with pytest.raises(RuntimeError) as excinfo:
|
||||||
assert response.status_code == 404
|
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):
|
def test_read_empty_flows(client: TestClient):
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ def test_init_build(client):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"api/v1/build/init", json={"id": "test", "data": {"key": "value"}}
|
"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"}
|
assert response.json() == {"flowId": "test"}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue