Skip to content

Commit

Permalink
Fix bug in app_or_component_selector callback (#348)
Browse files Browse the repository at this point in the history
* Fix bug in app_or_component_selector callback
  • Loading branch information
bsquizz authored Jan 25, 2024
1 parent 7cc975a commit d0fa42d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ def custom_formatwarning(msg, *args, **kwargs):
check_pypi()


@main.group(hidden=True)
def test():
"""
Used for unit testing
"""
pass


@main.group()
def namespace():
"""Perform operations related to namespace reservation"""
Expand Down Expand Up @@ -415,7 +423,7 @@ def _app_or_component_selector(ctx, param, this_value):
# set default value for --remove-resources to 'all' if option was unspecified
# set default value for --no-remove-dependencies to 'all' if option was unspecified
options_w_defaults = ("remove_resources", "no_remove_dependencies")
if this_param_name in options_w_defaults and this_value.empty:
if this_param_name in options_w_defaults and this_value.empty and other_value.empty:
this_value.select_all = True

return this_value
Expand Down Expand Up @@ -1041,6 +1049,18 @@ def _cmd_pool_types():
click.echo("\n".join(get_namespace_pools()))


def _get_return_args(*args, **kwargs):
"""Dummy function used for unit testing process options"""
pass


@test.command("process", hidden=True)
@options(_process_options)
def _cmd_test_process(*args, **kwargs):
"""Dummy command used for unit testing process options"""
_get_return_args(*args, **kwargs)


@main.command("process")
@options(_process_options)
@click.option(
Expand Down
32 changes: 32 additions & 0 deletions tests/test_bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,35 @@ def test_describe_wrong_ns(mocker):
print(result.output)
except FatalError:
assert True


def test_remove_defaults(mocker):
get_return_args = mocker.patch("bonfire.bonfire._get_return_args")

runner = CliRunner()
result = runner.invoke(bonfire.test, ["process", "some-app"])
assert result.exit_code == 0

call = get_return_args.call_args
assert call
_, kwargs = call
assert kwargs["remove_resources"].select_all is True
assert kwargs["no_remove_resources"].select_all is False
assert kwargs["remove_dependencies"].select_all is False
assert kwargs["no_remove_dependencies"].select_all is True


def test_remove_resources_all(mocker):
get_return_args = mocker.patch("bonfire.bonfire._get_return_args")

runner = CliRunner()
result = runner.invoke(bonfire.test, ["process", "some-app", "--no-remove-resources", "all"])
assert result.exit_code == 0

call = get_return_args.call_args
assert call
_, kwargs = call
assert kwargs["remove_resources"].select_all is False
assert kwargs["no_remove_resources"].select_all is True
assert kwargs["remove_dependencies"].select_all is False
assert kwargs["no_remove_dependencies"].select_all is True

0 comments on commit d0fa42d

Please sign in to comment.