Skip to content

Commit

Permalink
Fix: allow configure to run without an active env (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran authored Mar 13, 2024
2 parents 9bfec47 + 66c6216 commit 4e90166
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions littlepay/commands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def configure(config_path: str | Path = None) -> int:
print(f"Envs: {', '.join(config.envs.keys())}")
print(f"Participants: {', '.join(config.participants.keys())}")

if config.active_participant_id == "":
print(f"❓ Active: {config.active_env_name}, [no participant]")
if config.active_env_name == "" or config.active_participant_id == "":
env = config.active_env_name if config.active_env_name else "[no env]"
participant = config.active_participant_id if config.active_participant_id else "[no participant]"
print(f"❓ Active: {env}, {participant}")
return RESULT_SUCCESS

try:
Expand Down
9 changes: 6 additions & 3 deletions littlepay/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def active_env(self) -> dict:
Returns (dict):
Configuration data for the active environment.
"""
return self.envs[self.active_env_name]
active_env_name = self.active_env_name
if not active_env_name:
raise ValueError("Missing active env")
return self.envs[active_env_name]

@property
def active_participant(self) -> dict:
Expand All @@ -119,8 +122,8 @@ def active_credentials(self) -> dict:

@property
def active_env_name(self) -> str:
"""The active environment's name. By default, the QA environment."""
return self.active.get("env", ENV_QA)
"""The active environment's name."""
return self.active.get("env", "")

@active_env_name.setter
def active_env_name(self, value: str):
Expand Down
12 changes: 10 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from littlepay.config import (
DEFAULT_CONFIG,
DEFAULT_CREDENTIALS,
ENV_QA,
_get_current_path,
_read_config,
_write_config,
Expand Down Expand Up @@ -124,7 +123,7 @@ def test_Config_active_env_name_default():
config = Config()
config.active = {}

assert config.active_env_name == ENV_QA
assert config.active_env_name == ""


def test_Config_active_env_name_update():
Expand Down Expand Up @@ -159,6 +158,15 @@ def test_Config_active_env():
assert config.active_env == "the environment"


def test_Config_active_missing():
config = Config()
config.active = {}
config.envs = {"qa": "qa environment"}

with pytest.raises(ValueError):
config.active_env


def test_Config_active_participant_id(mocker):
config = Config()
config.active = {"participant": "active_participant"}
Expand Down

0 comments on commit 4e90166

Please sign in to comment.