From 482b6a633b7411eb2a687bde54d98ee36b4d0cc0 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Mon, 29 Jan 2024 22:07:36 +0000 Subject: [PATCH] Added environ tests --- tests/__init__.py | 3 ++- tests/general/test_env.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/general/test_env.py diff --git a/tests/__init__.py b/tests/__init__.py index e8b9fa2..2005eed 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,5 @@ import os # Setup test environment variables -os.environ["ENVIRON"] = "test" +if os.environ.get("ENVIRON") is None: + os.environ["ENVIRON"] = "test" diff --git a/tests/general/test_env.py b/tests/general/test_env.py new file mode 100644 index 0000000..ea89775 --- /dev/null +++ b/tests/general/test_env.py @@ -0,0 +1,28 @@ +from os import environ +from warnings import warn + +# Tests environment variables used within the projects domain are +# set in the correct environment + +VARS = ['ENVIRON', 'APPSECRET', 'FILESTORE'] + + +def test_env_vars(): + """ Test that required environment variables are set + ahead of runtime + """ + for var in VARS: + env = environ.get(var) + + # Check to see what variable we are comparing + if env is None: + warn(f"Variable {var} is not set!") + + +def test_environment_var_state(): + """ Tests that the 'ENVIRON' Environment variable + is in a correct state + """ + var = environ.get('ENVIRON') + assert var is not None + assert (var == "test" or var == "prod")