Skip to content
Snippets Groups Projects
Commit fb6afa95 authored by Razvan Vass's avatar Razvan Vass
Browse files

You must to have .env in the main folder

parent ff7ba139
1 merge request!9You must to have .env in the main folder
Pipeline #65134 passed with stages
in 1 minute and 31 seconds
...@@ -7,16 +7,16 @@ import os ...@@ -7,16 +7,16 @@ import os
def test_load_config_from_env(): def test_load_config_from_env():
# Case 1: Test if function raises exception for missing GRAFANA_API_KEY # Case 1: Test if function raises exception for missing GRAFANA_API_KEY
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
load_config_from_env(env_path=".env") load_config_from_env(env_path="../.env")
assert str(e.value) == "GRAFANA_API_KEY is None or not defined in the .env file" assert str(e.value) == "GRAFANA_API_KEY is None or not defined in the .env file"
# Case 2: Test if function raises exception for missing GRAFANA_SERVER # Case 2: Test if function raises exception for missing GRAFANA_SERVER
with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key"}): with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key"}):
with pytest.raises(ValueError) as e: with pytest.raises(ValueError) as e:
load_config_from_env(env_path=".env") load_config_from_env(env_path="../.env")
assert str(e.value) == "GRAFANA_SERVER is None or not defined in the .env file" assert str(e.value) == "GRAFANA_SERVER is None or not defined in the .env file"
# Case 3: Test if function returns expected values when both variables are defined # Case 3: Test if function returns expected values when both variables are defined
with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key", "GRAFANA_SERVER": "server_url"}): with patch.dict(os.environ, {"GRAFANA_API_KEY": "api_key", "GRAFANA_SERVER": "server_url"}):
result = load_config_from_env(env_path=".env") result = load_config_from_env(env_path="../.env")
assert result == ("server_url", "api_key") assert result == ("server_url", "api_key")
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment