From d728528033c2258e3dabc97b6c3587b3eff3eb00 Mon Sep 17 00:00:00 2001 From: optk2k Date: Fri, 12 Jan 2024 07:57:58 +0300 Subject: [PATCH] add assets path --- df_designer/__main__.py | 2 ++ df_designer/main.py | 7 +++++++ df_designer/settings.py | 4 ++-- df_designer/static/assets/for_assets_file.txt | 0 tests/test_main.py | 8 ++++++-- 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 df_designer/static/assets/for_assets_file.txt diff --git a/df_designer/__main__.py b/df_designer/__main__.py index 57678d42..ce2284d8 100644 --- a/df_designer/__main__.py +++ b/df_designer/__main__.py @@ -21,8 +21,10 @@ def meta(): def run_app( ip_address: str = app.conf_host, port: int = app.conf_port, + dir_logs: str = app.dir_logs, ): """Run the application.""" + app.dir_logs = dir_logs config = uvicorn.Config( app=app.conf_app, host=ip_address, diff --git a/df_designer/main.py b/df_designer/main.py index 635a8e81..13f449be 100644 --- a/df_designer/main.py +++ b/df_designer/main.py @@ -12,6 +12,13 @@ StaticFiles(directory=app.static_files), name="static", ) + +app.mount( + "/assets", + StaticFiles(directory=app.static_assets), + name="assets", +) + # TODO: добавить версию v1 # TODO: заглушка для dff # TODO: тесты дописать diff --git a/df_designer/settings.py b/df_designer/settings.py index 5db0582f..e46bd848 100644 --- a/df_designer/settings.py +++ b/df_designer/settings.py @@ -2,12 +2,11 @@ from fastapi import FastAPI -app = FastAPI() - class Application(FastAPI): package_dir = Path(__file__).absolute() static_files = package_dir.with_name("static") + static_assets = static_files.joinpath("assets") start_page = static_files.joinpath("index.html") work_directory = "." path_to_save = Path(work_directory).joinpath("flows.json") @@ -17,6 +16,7 @@ class Application(FastAPI): conf_port = 8000 conf_log_level = "info" conf_reload = True + dir_logs = "logs" app = Application() diff --git a/df_designer/static/assets/for_assets_file.txt b/df_designer/static/assets/for_assets_file.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_main.py b/tests/test_main.py index 16b3bbf0..6e2aaef3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -86,7 +86,11 @@ def test_settings(): assert app.conf_port == 8000 assert app.conf_log_level == "info" assert app.conf_reload is True + assert app.dir_logs == "logs" + assert app.static_files == app.package_dir.with_name("static") + assert app.static_assets == app.static_files.joinpath("assets") -# def test_settings_path_to_save(): -# assert app.path_to_save == Path(app.work_directory).joinpath("flows.json") +# TODO: test work directory +# TODO: path_to_save +# TODO: test assets path