From 36a7ba4ad5a589c75beec7cfa583b7cadea47545 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 09:45:09 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat(test=5Fcli.py):=20add=20tes?= =?UTF-8?q?ts=20for=20server=20functionality=20and=20command=20line=20opti?= =?UTF-8?q?ons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🚀 feat(test_cli.py): add test for checking database URL option 🚀 feat(test_cli.py): add test for checking components path option --- tests/test_cli.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 000000000..f1d5f193c --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,49 @@ +from pathlib import Path +from langflow.__main__ import app +import pytest + +import requests +import multiprocessing +import time +from langflow.services import utils + + +@pytest.fixture(scope="module") +def default_settings(): + return [ + "--backend-only", + "--no-open-browser", + ] + + +def test_server(default_settings): + p = multiprocessing.Process( + target=app, + args=(["--host", "localhost", "--port", "8982", *default_settings],), + ) + p.start() + time.sleep(5) # allow some time for the server to start + + response = requests.get( + "http://localhost:8982/health" + ) # assuming a /health endpoint exists + assert response.status_code == 200 + + p.terminate() + + +def test_database_url(runner): + result = runner.invoke(app, ["--database-url", "sqlite:///test.db"]) + assert result.exit_code == 2, result.stdout + assert "No such option: --database-url" in result.output + + +def test_components_path(runner, client, default_settings): + result = runner.invoke( + app, + ["--components-path", "./", *default_settings], + ) + assert result.exit_code == 0, result.stdout + settings_manager = utils.get_settings_manager() + path = Path("./") + assert path in settings_manager.settings.COMPONENTS_PATH