def test_template_helper_get_mint_bucket_name(monkeypatch): monkeypatch.setattr('senza.templates._helper.get_account_id', MagicMock(return_value=123)) monkeypatch.setattr('senza.templates._helper.get_account_alias', MagicMock(return_value='myorg-foobar')) s3 = MagicMock() s3.return_value.Bucket.return_value.name = 'myorg-stups-mint-123-myregion' monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name( 'myregion'), 'Find Mint Bucket' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-otherregion' == get_mint_bucket_name('otherregion'), \ 'Return Name of Bucket, if no other Bucket found' exist_bucket = MagicMock() exist_bucket.name = 'myorg-stups-mint-123-myregion' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() s3.return_value.buckets.all.return_value = [exist_bucket] monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name( 'otherregion'), 'Find Mint bucket in other Region'
def test_template_helper_get_mint_bucket_name(monkeypatch): iam = MagicMock() iam.list_roles.return_value = {'list_roles_response': {'list_roles_result': {'is_truncated': 'false', 'roles': [ {'arn': 'arn:aws:iam::123:role/app-delivery'}]}}} iam.get_account_alias.return_value = { 'list_account_aliases_response': {'list_account_aliases_result': {'account_aliases': ['myorg-foobar']}} } monkeypatch.setattr('boto.iam.connect_to_region', MagicMock(return_value=iam)) s3 = MagicMock() s3.return_value.Bucket.return_value.name = 'myorg-stups-mint-123-myregion' monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name('myregion'), 'Find Mint Bucket' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() monkeypatch.setattr('boto3.resource', s3) assert('myorg-stups-mint-123-otherregion' == get_mint_bucket_name('otherregion'), 'Return Name of Bucket, if no other Bucket found') exist_bucket = MagicMock() exist_bucket.name = 'myorg-stups-mint-123-myregion' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() s3.return_value.buckets.all.return_value = [exist_bucket] monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name('otherregion'), 'Find Mint bucket in other Region'
def MintBucket(self) -> str: """ Returns the mintbucket for the current account """ if self.__MintBucket is None: self.__MintBucket = get_mint_bucket_name(self.Region) return self.__MintBucket
def test_template_helper_get_mint_bucket_name(monkeypatch): iam = MagicMock() iam.list_roles.return_value = {'list_roles_response': {'list_roles_result': {'is_truncated': 'false', 'roles': [ {'arn': 'arn:aws:iam::123:role/app-delivery'}]}}} iam.get_account_alias.return_value = { 'list_account_aliases_response': {'list_account_aliases_result': {'account_aliases': ['myorg-foobar']}} } monkeypatch.setattr('boto.iam.connect_to_region', MagicMock(return_value=iam)) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name('myregion')
def test_template_helper_get_mint_bucket_name(monkeypatch): monkeypatch.setattr('senza.templates._helper.get_account_id', MagicMock(return_value=123)) monkeypatch.setattr('senza.templates._helper.get_account_alias', MagicMock(return_value='myorg-foobar')) s3 = MagicMock() s3.return_value.Bucket.return_value.name = 'myorg-stups-mint-123-myregion' monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name('myregion'), 'Find Mint Bucket' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() monkeypatch.setattr('boto3.resource', s3) assert('myorg-stups-mint-123-otherregion' == get_mint_bucket_name('otherregion'), 'Return Name of Bucket, if no other Bucket found') exist_bucket = MagicMock() exist_bucket.name = 'myorg-stups-mint-123-myregion' s3 = MagicMock() s3.return_value.Bucket.return_value.load.side_effect = Exception() s3.return_value.buckets.all.return_value = [exist_bucket] monkeypatch.setattr('boto3.resource', s3) assert 'myorg-stups-mint-123-myregion' == get_mint_bucket_name('otherregion'), 'Find Mint bucket in other Region'