diff --git a/tests/conftest.py b/tests/conftest.py index b9d656ed2..37657d8c7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ from pathlib import Path import pytest +from fastapi.testclient import TestClient def pytest_configure(): @@ -9,3 +10,14 @@ def pytest_configure(): pytest.COMPLEX_EXAMPLE_PATH = ( Path(__file__).parent.absolute() / "data" / "complex_example.json" ) + + +# Create client fixture for FastAPI +@pytest.fixture(scope="module") +def client(): + from langflow.main import create_app + + app = create_app() + + with TestClient(app) as client: + yield client diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py new file mode 100644 index 000000000..20e860575 --- /dev/null +++ b/tests/test_endpoints.py @@ -0,0 +1,22 @@ +# # build router +# router = APIRouter() + + +# @router.get("/all") +# def get_all(): +# return build_langchain_types_dict() + + +# Buil test for /all endpoint +from langflow.utils.constants import CUSTOM_TOOLS +from fastapi.testclient import TestClient + + +def test_get_all(client: TestClient): + response = client.get("/all") + assert response.status_code == 200 + json_response = response.json() + # We need to test the custom nodes + assert "ZeroShotPrompt" in json_response["prompts"] + # All CUSTOM_TOOLS(dict) should be in the response + assert all(tool in json_response["tools"] for tool in CUSTOM_TOOLS.keys()) diff --git a/tests/test_graph.py b/tests/test_graph.py index bbcaffa85..3bdf72c45 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -262,7 +262,7 @@ def test_build(): # # and use the output of that build as the value for the param # # if the value is not a node, then we use the value as the param # # and continue - # # Another aspect is that the module_type is the class that we need to import + # # Another aspect is that the node_type is the class that we need to import # # and instantiate with these built params # # Build each node in the params dict @@ -273,7 +273,7 @@ def test_build(): # # Get the class from LANGCHAIN_TYPES_DICT # # and instantiate it with the params # # and return the instance - # return LANGCHAIN_TYPES_DICT[self.module_type](**self.params) + # return LANGCHAIN_TYPES_DICT[self.node_type](**self.params) graph = get_graph() assert isinstance(graph, Graph) # Now we test the build method