Skip to content

Commit

Permalink
chore(config): remove unneeded reset arg
Browse files Browse the repository at this point in the history
users can delete their config or target a new file
  • Loading branch information
thekaveman committed Aug 24, 2023
1 parent 31ffe4c commit 655f8dd
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
5 changes: 3 additions & 2 deletions littlepay/commands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
from littlepay.config import ENV_PROD, Config


def configure(config_path: str | Path = None, reset: bool = False) -> int:
def configure(config_path: str | Path = None) -> int:
"""Get or set project configuration.
Returns:
A value indicating whether or not the current environment and participant are configured.
"""
if config_path is None:
config_path = Config.current_path()
config = Config(config_path, reset=reset)

config = Config(config_path)
current_config_path = Config.current_path()

env = config.active_env_name()
Expand Down
6 changes: 2 additions & 4 deletions littlepay/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ class Config:
read = staticmethod(_read_config)
write = staticmethod(_write_config)

def __init__(self, config_file_path: str | Path = None, reset: bool = False):
def __init__(self, config_file_path: str | Path = None):
"""Initialize a new Config instance, reading from the given path or a default location.
Args:
config_file_path (str|Path): Path to a readable config file. If None, the default is used.
reset (bool): True to reset the configuration to the default.
"""
if config_file_path is None or config_file_path == "":
config_file_path = Config.current_path()
if isinstance(config_file_path, str):
config_file_path = Path(config_file_path)
if not config_file_path.exists() or reset:
if not config_file_path.exists():
print(f"Creating config file: {config_file_path.resolve()}")
config_file_path.parent.mkdir(parents=True, exist_ok=True)
Config.write(DEFAULT_CONFIG, config_file_path)
Expand Down
3 changes: 1 addition & 2 deletions littlepay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def _subcmd(name, help) -> argparse.ArgumentParser:
dest="config_path",
help="Path to a readable and writeable config file to use. File will be created if it does not exist.",
)
config_parser.add_argument("--reset", action="store_true", default=False, help="Reset the configuration.")

switch_parser = _subcmd("switch", help="Switch the active environment or participant.")
switch_parser.add_argument("switch_type", choices=CONFIG_TYPES, help="The type of object to switch", metavar="TYPE")
Expand All @@ -46,7 +45,7 @@ def _subcmd(name, help) -> argparse.ArgumentParser:
args = parser.parse_args(argv)

if args.command == "config":
return configure(args.config_path, args.reset)
return configure(args.config_path)
elif args.command == "switch":
return switch(args.switch_type, args.switch_arg)

Expand Down
15 changes: 0 additions & 15 deletions tests/commands/test_configure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

import pytest

from littlepay.commands import RESULT_FAILURE, RESULT_SUCCESS
Expand Down Expand Up @@ -99,16 +97,3 @@ def test_configure_participant_credentials_prod(mock_Config, capfd):
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)
assert custom_config_file.exists()
assert content in custom_config_file.read_text()

res = configure(custom_config_file, reset=True)

assert res == RESULT_FAILURE
assert custom_config_file.exists()
assert content not in custom_config_file.read_text()
14 changes: 0 additions & 14 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,6 @@ def test_Config_exists(custom_config_file: Path):
assert config.other_data == "more config"


def test_Config_reset(custom_config_file: Path):
assert not custom_config_file.exists()
custom_config_file.write_text('{"data": "the config"}')
assert custom_config_file.exists()

config = Config(custom_config_file, reset=True)

assert custom_config_file.exists()
assert config.active == DEFAULT_CONFIG["active"]
assert config.envs == DEFAULT_CONFIG["envs"]
assert config.participants == DEFAULT_CONFIG["participants"]
assert not hasattr(config, "data")


def test_Config_active_env_name(mocker):
config = Config()
config.active = mocker.Mock()
Expand Down

0 comments on commit 655f8dd

Please sign in to comment.