From c5c6d860fd04139ed9cb9b1060ec94b10c4c470f Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Thu, 25 Jul 2024 17:20:36 +0000 Subject: [PATCH] test(secrets): add a dummy secrets file --- tests/conftest.py | 31 ++++++++++++++++--------------- tests/data/secrets.json | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 tests/data/secrets.json diff --git a/tests/conftest.py b/tests/conftest.py index 2d22667..0225933 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,8 @@ from os import path from os import makedirs from typing import Generator from fastapi.testclient import TestClient +from shutil import copyfile + from selfprivacy_api.models.tokens.token import Token from selfprivacy_api.utils.huey import huey @@ -85,24 +87,23 @@ def redis_repo_with_tokens(): ) +def clone_global_file(filename, tmpdir) -> str: + source_path = path.join(global_data_dir(), filename) + clone_path = path.join(tmpdir, filename) + + copyfile(source_path, clone_path) + return clone_path + + @pytest.fixture def generic_userdata(mocker, tmpdir): - filename = "turned_on.json" - secrets_filename = "secrets.json" - - source_path = path.join(global_data_dir(), filename) - userdata_path = path.join(tmpdir, filename) - secrets_path = path.join(tmpdir, secrets_filename) - - with open(secrets_path, "w") as file: - file.write("{}") - - with open(userdata_path, "w") as file: - with open(source_path, "r") as source: - file.write(source.read()) - + userdata_path = clone_global_file("turned_on.json", tmpdir) mock = mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=userdata_path) - mocker.patch("selfprivacy_api.utils.SECRETS_FILE", new=secrets_path) + mock = mocker.patch("selfprivacy_api.services.USERDATA_FILE", new=userdata_path) + + secrets_path = clone_global_file("secrets.json", tmpdir) + mock = mocker.patch("selfprivacy_api.utils.SECRETS_FILE", new=secrets_path) + mock = mocker.patch("selfprivacy_api.services.SECRETS_FILE", new=secrets_path) return mock diff --git a/tests/data/secrets.json b/tests/data/secrets.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/data/secrets.json @@ -0,0 +1 @@ +{}