Esempio n. 1
0
    def test_run_async(
        self,
        fx_deployments: YamlLoaderDeployment,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
    ) -> None:
        """Test run async."""
        mocker.patch(f"{MODULE}.aws")
        # ensure that mock.MagicMock is used for backported features
        mock_module = mocker.patch(f"{MODULE}.Module", MagicMock())
        definition = fx_deployments.load("simple_parallel_regions")
        runway_context._use_concurrent = True
        # ensure that mock.MagicMock is used for backported features
        mock_resolve = mocker.patch.object(definition, "resolve", MagicMock())
        mocker.patch.object(Deployment, "validate_account_credentials")
        obj = Deployment(context=runway_context, definition=definition)

        assert not obj.run("destroy", "us-west-2")

        new_ctx = mock_resolve.call_args.args[0]
        assert new_ctx != runway_context
        assert new_ctx.command == "destroy" and runway_context.command != "destroy"
        assert (new_ctx.env.aws_region == "us-west-2"
                and runway_context.env.aws_region != "us-west-2")
        assert mock_module.run_list.call_args.kwargs["context"] == new_ctx
Esempio n. 2
0
    def test_run(
        self,
        fx_deployments: YamlLoaderDeployment,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
    ) -> None:
        """Test run."""
        mock_aws = mocker.patch(f"{MODULE}.aws")
        mock_module = mocker.patch(f"{MODULE}.Module")
        definition = fx_deployments.load("min_required")
        mock_resolve = mocker.patch.object(definition, "resolve")
        mock_validate = mocker.patch.object(Deployment,
                                            "validate_account_credentials")
        obj = Deployment(context=runway_context, definition=definition)

        assert not obj.run("deploy", "us-west-2")

        assert runway_context.command == "deploy"
        assert runway_context.env.aws_region == "us-west-2"
        mock_resolve.assert_called_once_with(runway_context,
                                             variables=obj._variables)
        mock_validate.assert_called_once_with(runway_context)
        mock_aws.AssumeRole.assert_called_once_with(runway_context)
        mock_aws.AssumeRole().__enter__.assert_called_once()
        mock_module.run_list.assert_called_once_with(
            action="deploy",
            context=runway_context,
            deployment=definition,
            future=obj._future,
            modules=ANY,  # list of module objects change
            variables=obj._variables,
        )
Esempio n. 3
0
    def test_run(
        self, mock_module, mock_aws, fx_deployments, monkeypatch, runway_context
    ):
        """Test run."""
        mock_resolve = MagicMock()
        mock_validate = MagicMock()
        definition = fx_deployments.load("min_required")
        monkeypatch.setattr(definition, "resolve", mock_resolve)
        monkeypatch.setattr(Deployment, "validate_account_credentials", mock_validate)
        obj = Deployment(context=runway_context, definition=definition)

        assert not obj.run("deploy", "us-west-2")

        assert runway_context.command == "deploy"
        assert runway_context.env.aws_region == "us-west-2"
        mock_resolve.assert_called_once_with(runway_context, obj._variables)
        mock_validate.assert_called_once_with(runway_context)
        mock_aws.AssumeRole.assert_called_once_with(runway_context)
        mock_aws.AssumeRole().__enter__.assert_called_once()
        mock_module.run_list.assert_called_once_with(
            action="deploy",
            context=runway_context,
            deployment=definition,
            future=obj._future,
            modules=definition.modules,
            variables=obj._variables,
        )
Esempio n. 4
0
    def test_run_async(
        self, mock_module, _mock_aws, fx_deployments, monkeypatch, runway_context
    ):
        """Test run async."""
        mock_resolve = MagicMock()
        definition = fx_deployments.load("simple_parallel_regions")
        runway_context._use_concurrent = True
        monkeypatch.setattr(definition, "resolve", mock_resolve)
        monkeypatch.setattr(Deployment, "validate_account_credentials", MagicMock())
        obj = Deployment(context=runway_context, definition=definition)

        assert not obj.run("destroy", "us-west-2")

        new_ctx = mock_resolve.call_args.args[0]
        assert new_ctx != runway_context
        assert new_ctx.command == "destroy" and runway_context.command != "destroy"
        assert (
            new_ctx.env.aws_region == "us-west-2"
            and runway_context.env.aws_region != "us-west-2"
        )
        assert mock_module.run_list.call_args.kwargs["context"] == new_ctx