Skip to content

Commit

Permalink
chore(config): alert when env=prod
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Aug 24, 2023
1 parent 8df63c5 commit de9e3a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 4 additions & 3 deletions littlepay/commands/configure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

from littlepay.commands import RESULT_FAILURE, RESULT_SUCCESS
from littlepay.config import Config
from littlepay.config import ENV_PROD, Config


def configure(config_path: str | Path = None, reset: bool = False) -> int:
Expand Down Expand Up @@ -32,8 +32,9 @@ def configure(config_path: str | Path = None, reset: bool = False) -> int:
credentials = None

if credentials is None:
print(f"Active: {env}, {participant} [missing credentials]")
print(f"Active: {env}, {participant} [missing credentials]".strip())
return RESULT_FAILURE
else:
print(f"Active: {env}, {participant}")
alert = "⚠️ " if env == ENV_PROD else ""
print(f"Active: {alert}{env}, {participant}".strip())
return RESULT_SUCCESS
17 changes: 15 additions & 2 deletions tests/commands/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from littlepay.commands import RESULT_FAILURE, RESULT_SUCCESS
from littlepay.commands.configure import configure
from littlepay.config import DEFAULT_CREDENTIALS
from littlepay.config import DEFAULT_CREDENTIALS, ENV_PROD


@pytest.fixture
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_configure_participant_credentials_missing(mock_Config, capfd):
assert "Active: env123, participant123 [missing credentials]" in capture.out


def test_configure_participant_no_credentials(mock_Config, capfd):
def test_configure_participant_credentials_None(mock_Config, capfd):
mock_Config.active_env_name.return_value = "env123"
mock_Config.active_participant_id.return_value = "participant123"
mock_Config.active_credentials.return_value = None
Expand All @@ -88,6 +88,19 @@ def test_configure_participant_no_credentials(mock_Config, capfd):
assert "Active: env123, participant123 [missing credentials]" in capture.out


def test_configure_participant_credentials_prod(mock_Config, capfd):
mock_Config.active_env_name.return_value = ENV_PROD
mock_Config.active_participant_id.return_value = "participant123"
mock_Config.active_credentials.return_value = DEFAULT_CREDENTIALS

res = configure()
capture = capfd.readouterr()

assert res == RESULT_SUCCESS
assert "Active: ⚠️ prod, participant123" in capture.out
assert "[missing credentials]" not in capture.out


def test_configure_reset(custom_config_file: Path):
content = "Custom config content written here"
custom_config_file.write_text(content)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_littlepay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess

from littlepay.commands import RESULT_SUCCESS
from littlepay.commands import RESULT_FAILURE


def test_littlepay(capfd):
Expand All @@ -11,7 +11,7 @@ def test_littlepay(capfd):
assert "Envs:" in capture.out
assert "Participants:" in capture.out
assert "Active:" in capture.out
assert res == RESULT_SUCCESS
assert res == RESULT_FAILURE


def test_config(capfd):
Expand All @@ -22,4 +22,4 @@ def test_config(capfd):
assert "Envs:" in capture.out
assert "Participants:" in capture.out
assert "Active:" in capture.out
assert res == RESULT_SUCCESS
assert res == RESULT_FAILURE

0 comments on commit de9e3a6

Please sign in to comment.