예제 #1
0
    def testCreateBucketNotExists(self):
        m = self.storage_messages
        bucket_name = 'gke-issuer-0'
        project = 'project'

        self.mock_storage_client.buckets.Insert.Expect(
            request=m.StorageBucketsInsertRequest(bucket=m.Bucket(
                iamConfiguration=m.Bucket.IamConfigurationValue(
                    uniformBucketLevelAccess=m.Bucket.IamConfigurationValue.
                    UniformBucketLevelAccessValue(enabled=True)),
                name=bucket_name),
                                                  project=project),
            response=m.Bucket(name=bucket_name))

        api_util._CreateBucketIfNotExists(self.mock_storage_client,
                                          bucket_name, project)
예제 #2
0
    def testCreateBucketException(self):
        m = self.storage_messages
        bucket_name = 'gke-issuer-0'
        project = 'project'

        self.mock_storage_client.buckets.Insert.Expect(
            request=m.StorageBucketsInsertRequest(bucket=m.Bucket(
                iamConfiguration=m.Bucket.IamConfigurationValue(
                    uniformBucketLevelAccess=m.Bucket.IamConfigurationValue.
                    UniformBucketLevelAccessValue(enabled=True)),
                name=bucket_name),
                                                  project=project),
            exception=_http_500_exception)

        with self.assertRaisesRegex(
                exceptions.Error, 'Unable to create bucket '
                '{}'.format(bucket_name)):
            api_util._CreateBucketIfNotExists(self.mock_storage_client,
                                              bucket_name, project)