def test_bucket_load_encounters_other_exception(self): self.client.list_buckets.side_effect = ClientError( {'Error': {'Code': 'ExpiredToken', 'Message': 'The provided token has expired.'}}, 'ListBuckets') with self.assertRaises(ClientError): inject.bucket_load(self.resource)
def test_bucket_load_encounters_access_exception(self): self.client.list_buckets.side_effect = ClientError( {'Error': {'Code': 'AccessDenied', 'Message': 'Access Denied'}}, 'ListBuckets') inject.bucket_load(self.resource) self.assertEqual(self.resource.meta.data, {})
def test_normalized_op_returns_error_response(self): # Client objects normally throw exceptions when an error # occurs, but we need to return the parsed error response. client_method = mock.Mock() op = NormalizedOperationMethod(client_method) parsed_response = {'Error': {'Code': 'Foo', 'Message': 'bar'}} exception = ClientError(parsed_response, 'OperationName') client_method.side_effect = exception actual_response = op(Foo='a', Bar='b') self.assertEqual(actual_response, parsed_response)
def bucket_load(self, *args, **kwargs): """ Calls s3.Client.list_buckets() to update the attributes of the Bucket resource. """ # The docstring above is phrased this way to match what the autogenerated # docs produce. # We can't actually get the bucket's attributes from a HeadBucket, # so we need to use a ListBuckets and search for our bucket. response = self.meta.client.list_buckets() for bucket_data in response['Buckets']: if bucket_data['Name'] == self.name: self.meta.data = bucket_data break else: raise ClientError({'Error': { 'Code': '404', 'Message': 'NotFound' }}, 'ListBuckets')