From 460849bd3d15954170415e8a7d2c2de5b2e484cb Mon Sep 17 00:00:00 2001 From: hay-kot Date: Tue, 30 Mar 2021 11:13:55 -0800 Subject: [PATCH] add tools test --- tests/integration_tests/test_recipe_routes.py | 1 + tests/unit_tests/test_config.py | 50 +++++++++++++++++-- tests/unit_tests/test_init_db.py | 0 tests/utils/recipe_data.py | 1 + 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/unit_tests/test_init_db.py diff --git a/tests/integration_tests/test_recipe_routes.py b/tests/integration_tests/test_recipe_routes.py index ef4039c70..0c886118e 100644 --- a/tests/integration_tests/test_recipe_routes.py +++ b/tests/integration_tests/test_recipe_routes.py @@ -52,6 +52,7 @@ def test_read_update(api_client: TestClient, api_routes: AppRoutes, recipe_data, {"title": "My Test Title2", "text": "My Test Text2"}, ] recipe["notes"] = test_notes + recipe["tools"] = ["one tool", "two tool"] test_categories = ["one", "two", "three"] recipe["recipeCategory"] = test_categories diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 347f3efc6..8651191ac 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -1,6 +1,48 @@ -from mealie.core.config import determine_secrets +from pathlib import Path -def test_determine_secret(monkeypatch): - secret = determine_secrets() +import pytest +from mealie.core.config import CWD, DATA_DIR, AppDirectories, AppSettings, determine_data_dir, determine_secrets - \ No newline at end of file + +def test_non_default_settings(monkeypatch): + monkeypatch.setenv("DEFAULT_GROUP", "Test Group") + monkeypatch.setenv("DEFAULT_PASSWORD", "Test Password") + monkeypatch.setenv("API_PORT", "8000") + monkeypatch.setenv("API_DOCS", False) + + app_dirs = AppDirectories(CWD, DATA_DIR) + app_settings = AppSettings(app_dirs) + + assert app_settings.DEFAULT_GROUP == "Test Group" + assert app_settings.DEFAULT_PASSWORD == "Test Password" + assert app_settings.API_PORT == 8000 + assert app_settings.API == False + + assert app_settings.REDOC_URL is None + assert app_settings.DOCS_URL is None + + +def test_unknown_database(monkeypatch): + monkeypatch.setenv("DB_TYPE", "nonsense") + + with pytest.raises(Exception, match="Unable to determine database type. Acceptible options are 'sqlite'"): + app_dirs = AppDirectories(CWD, DATA_DIR) + AppSettings(app_dirs) + + +def test_secret_generation(tmp_path): + app_dirs = AppDirectories(CWD, DATA_DIR) + assert determine_secrets(app_dirs.DATA_DIR, False) == "shh-secret-test-key" + assert determine_secrets(app_dirs.DATA_DIR, True) != "shh-secret-test-key" + + + assert determine_secrets(tmp_path, True) != "shh-secret-test-key" + + +def test_set_data_dir(): + global CWD + PROD_DIR = Path("/app/data") + DEV_DIR = CWD.parent.parent.joinpath("dev", "data") + + assert determine_data_dir(True) == PROD_DIR + assert determine_data_dir(False) == DEV_DIR diff --git a/tests/unit_tests/test_init_db.py b/tests/unit_tests/test_init_db.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/utils/recipe_data.py b/tests/utils/recipe_data.py index 9c25c634d..32a472d7c 100644 --- a/tests/utils/recipe_data.py +++ b/tests/utils/recipe_data.py @@ -57,6 +57,7 @@ def get_raw_recipe(): ], "totalTime": "None", "prepTime": None, + "tools": ["test_tool"], "performTime": None, "slug": "", "categories": [],