-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_conf.py
69 lines (55 loc) · 1.77 KB
/
test_conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from unittest import mock
import pytest
from click.testing import CliRunner
from leverage import leverage
from leverage.conf import load
ROOT_ENV_FILE = """
# Project settings
PROJECT=foobar
# General
MFA_ENABLED=true
ENTRYPOINT=/bin/run
DEBUG=false
"""
ACC_ENV_FILE = """
# Environment settings
DEBUG=true
CONFIG_PATH=/home/user/.config/
"""
@pytest.mark.parametrize(
"write_files, expected_values",
[
( # Env files present
True,
{
"PROJECT": "foobar",
"MFA_ENABLED": "true",
"ENTRYPOINT": "/bin/run",
"DEBUG": "true",
"CONFIG_PATH": "/home/user/.config/",
},
),
(False, {}), # No env files
],
)
def test_load_config(monkeypatch, click_context, tmp_path, write_files, expected_values):
with click_context():
root_dir = tmp_path
account_dir = tmp_path / "account"
account_dir.mkdir()
monkeypatch.setattr("leverage.conf.get_root_path", lambda: root_dir.as_posix())
monkeypatch.setattr("leverage.conf.get_working_path", lambda: account_dir.as_posix())
if write_files:
(root_dir / "build.env").write_text(ROOT_ENV_FILE)
(account_dir / "build.env").write_text(ACC_ENV_FILE)
loaded_values = load()
assert dict(loaded_values) == expected_values
def test_version_validation():
"""
Test that we get a warning if we are working with a version lower than the required by the project.
"""
runner = CliRunner()
with mock.patch("leverage.conf.load", return_value={"LEVERAGE_CLI_VERSION": "99.9.9"}):
result = runner.invoke(leverage)
assert "is lower than the required minimum (99.9.9)" in result.output
assert result.exit_code == 0