diff --git a/sceptre/cli/update.py b/sceptre/cli/update.py index 419ffc66a..f685ecc68 100644 --- a/sceptre/cli/update.py +++ b/sceptre/cli/update.py @@ -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, diff --git a/tests/test_cli/test_cli_commands.py b/tests/test_cli/test_cli_commands.py index 08403e05e..4bcee0d18 100644 --- a/tests/test_cli/test_cli_commands.py +++ b/tests/test_cli/test_cli_commands.py @@ -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 = { @@ -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] @@ -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",