Skip to content

Commit

Permalink
jons-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-z3q committed Jun 23, 2024
1 parent 7f8810f commit 79570a5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion sceptre/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def update_command(

at_least_one_ready = False

for status in list(statuses.values()):
for status in statuses.values():
# Exit if change set fails to create
if status not in (
StackChangeSetStatus.READY,
Expand Down
89 changes: 55 additions & 34 deletions tests/test_cli/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,32 +514,15 @@ def test_stack_commands(self, command, success, yes_flag, exit_code):
run_command.assert_called_with()
assert result.exit_code == exit_code

@pytest.mark.parametrize(
"change_set_status,yes_flag,exit_code,verbose_flag",
[
(StackChangeSetStatus.READY, True, 0, True),
(StackChangeSetStatus.READY, True, 0, False),
(StackChangeSetStatus.READY, False, 0, True),
(StackChangeSetStatus.READY, False, 0, False),
(StackChangeSetStatus.NO_CHANGES, True, 0, True),
(StackChangeSetStatus.NO_CHANGES, False, 0, False),
(StackChangeSetStatus.NO_CHANGES, True, 0, False),
(StackChangeSetStatus.NO_CHANGES, False, 0, True),
(StackChangeSetStatus.DEFUNCT, True, 1, True),
(StackChangeSetStatus.DEFUNCT, False, 1, False),
(StackChangeSetStatus.DEFUNCT, True, 1, False),
(StackChangeSetStatus.DEFUNCT, False, 1, True),
],
)
def test_update_with_change_set(
self, change_set_status, yes_flag, exit_code, verbose_flag
):
@pytest.mark.parametrize("verbose_flag", [True, False])
def test_update_with_change_set_ready(self, verbose_flag):
create_command = self.mock_stack_actions.create_change_set
wait_command = self.mock_stack_actions.wait_for_cs_completion
execute_command = self.mock_stack_actions.execute_change_set
delete_command = self.mock_stack_actions.delete_change_set
describe_command = self.mock_stack_actions.describe_change_set

change_set_status = StackChangeSetStatus.READY
wait_command.return_value = change_set_status

response = {
Expand Down Expand Up @@ -571,16 +554,39 @@ def test_update_with_change_set(

describe_command.return_value = response

kwargs = {"args": ["update", "--change-set", "dev/vpc.yaml"]}
kwargs = {"args": ["update", "--change-set", "dev/vpc.yaml", "-y"]}
if verbose_flag:
kwargs["args"].append("-v")

result = self.runner.invoke(cli, **kwargs)

change_set_name = create_command.call_args[0][0]
assert "change-set" in change_set_name

wait_command.assert_called_once_with(change_set_name)
delete_command.assert_called_once_with(change_set_name)
execute_command.assert_called_once_with(change_set_name)
describe_command.assert_called_once_with(change_set_name)

output = result.output.splitlines()[0]
assert yaml.safe_load(output) == response
assert result.exit_code == 0

@pytest.mark.parametrize("yes_flag", [True, False])
def test_update_with_change_set_defunct(self, yes_flag):
create_command = self.mock_stack_actions.create_change_set
wait_command = self.mock_stack_actions.wait_for_cs_completion
delete_command = self.mock_stack_actions.delete_change_set

change_set_status = StackChangeSetStatus.DEFUNCT
wait_command.return_value = change_set_status

kwargs = {"args": ["update", "--change-set", "dev/vpc.yaml"]}
if yes_flag:
kwargs["args"].append("-y")
else:
kwargs["input"] = "y\n"

if verbose_flag:
kwargs["args"].append("-v")

result = self.runner.invoke(cli, **kwargs)

change_set_name = create_command.call_args[0][0]
Expand All @@ -589,19 +595,34 @@ def test_update_with_change_set(
wait_command.assert_called_once_with(change_set_name)
delete_command.assert_called_once_with(change_set_name)

if change_set_status == StackChangeSetStatus.READY:
execute_command.assert_called_once_with(change_set_name)
describe_command.assert_called_once_with(change_set_name)
output = result.output.splitlines()[0]
assert yaml.safe_load(output) == response
assert "Failed to create change set" in result.output
assert result.exit_code == 1

if change_set_status == StackChangeSetStatus.DEFUNCT:
assert "Failed to create change set" in result.output
@pytest.mark.parametrize("yes_flag", [True, False])
def test_update_with_change_set_no_changes(self, yes_flag):
create_command = self.mock_stack_actions.create_change_set
wait_command = self.mock_stack_actions.wait_for_cs_completion
delete_command = self.mock_stack_actions.delete_change_set

if change_set_status == StackChangeSetStatus.NO_CHANGES:
assert "No changes detected" in result.output
change_set_status = StackChangeSetStatus.NO_CHANGES
wait_command.return_value = change_set_status

assert result.exit_code == exit_code
kwargs = {"args": ["update", "--change-set", "dev/vpc.yaml"]}
if yes_flag:
kwargs["args"].append("-y")
else:
kwargs["input"] = "y\n"

result = self.runner.invoke(cli, **kwargs)

change_set_name = create_command.call_args[0][0]
assert "change-set" in change_set_name

wait_command.assert_called_once_with(change_set_name)
delete_command.assert_called_once_with(change_set_name)

assert "No changes detected" in result.output
assert result.exit_code == 0

@pytest.mark.parametrize(
"command, ignore_dependencies",
Expand Down

0 comments on commit 79570a5

Please sign in to comment.