Example #1
0
    def test_unsupported_project_type(
        self,
        get_component_name,
        Release,
        assume_role,
        build_account_scheme_s3,
        load_manifest,
        sys,
        rmtree,
        check_output,
    ):
        # Given
        account_scheme = MagicMock(spec=AccountScheme)
        account_scheme.default_region = 'eu-west-12'
        account_scheme.release_account = MagicMock(spec=Account)
        account_scheme.release_bucket = 'bucket'
        build_account_scheme_s3.return_value = (
            account_scheme,
            None,
        )

        check_output.return_value = 'hash\n'.encode('utf-8')

        # When / Then
        with self.assertRaises(UnknownProjectTypeError) as context:
            cli._run(
                ['release', '--platform-config', 'path/to/config', 'version'])

        expected_message = 'Unknown project type: {}'.format(
            load_manifest.return_value.type)

        assert expected_message in str(context.exception)
Example #2
0
    def test_component_flag_passed_but_no_upgrade_handled(
        self,
        get_component_name,
        run_release,
        assume_role,
        build_account_scheme_s3,
        load_manifest,
        sys,
        rmtree,
        check_output,
        migrate_state,
        Session,
    ):
        account_scheme = MagicMock(spec=AccountScheme)
        account_scheme.default_region = 'eu-west-12'
        account_scheme.release_account = MagicMock(spec=Account)
        account_scheme.release_account.alias = 'release'
        account_scheme.release_bucket = 'bucket'
        build_account_scheme_s3.return_value = (
            account_scheme,
            None,
        )

        check_output.return_value = 'hash\n'.encode('utf-8')

        cli._run([
            'release',
            '--platform-config',
            'path/to/config',
            'version',
            '--component',
            'a-component',
        ])

        migrate_state.assert_not_called()
Example #3
0
    def test_release_assumes_release_account_role(
        self,
        Session,
        build_account_scheme_s3,
        assume_role,
        run_release,
        load_manifest,
        check_output,
    ):

        # Given
        root_session = Mock()
        Session.return_value = root_session
        release_account_session = Mock()
        assume_role.return_value = release_account_session
        account_scheme = Mock()
        account_scheme.release_account.id = '1234567890'
        account_scheme.release_account.role = 'test-role'
        account_scheme.release_account.region_name = 'eu-west-13'
        account_scheme.default_region = 'eu-west-12'
        build_account_scheme_s3.return_value = (account_scheme, None)
        check_output.return_value = '[email protected]:org/component.git\n'\
            .encode('utf-8')

        # When
        cli._run(['release', '--platform-config', 'path/to/config', 'version'])

        # Then
        assume_role.assert_called_once_with(
            root_session,
            account_scheme.release_account,
        )
        run_release.assert_called_once_with(ANY, release_account_session,
                                            account_scheme, ANY, ANY)
Example #4
0
    def test_migrate_state_function_is_called(
        self,
        get_component_name,
        run_release,
        assume_role,
        build_account_scheme_s3,
        load_manifest,
        sys,
        rmtree,
        check_output,
        migrate_state,
        Session,
    ):
        account_scheme = MagicMock(spec=AccountScheme)
        account_scheme.default_region = 'eu-west-12'
        account_scheme.release_account = MagicMock(spec=Account)
        account_scheme.release_account.alias = 'release'
        account_scheme.release_bucket = 'bucket'
        old_account_scheme = MagicMock(spec=AccountScheme)
        old_account_scheme.default_region = 'eu-west-12'
        old_account_scheme.release_account = MagicMock(spec=Account)
        old_account_scheme.release_account.alias = 'old-release'
        old_account_scheme.release_bucket = 'bucket'
        old_account_scheme.raw_scheme = {}
        build_account_scheme_s3.return_value = (
            account_scheme,
            old_account_scheme,
        )

        check_output.return_value = 'hash\n'.encode('utf-8')

        cli._run(['release', '--platform-config', 'path/to/config', 'version'])

        migrate_state.assert_called_once_with(
            Session.return_value,
            account_scheme,
            old_account_scheme,
            load_manifest.return_value.team,
            get_component_name.return_value,
        )