Merge pull request #661 from braintreeps/fix-s3-errors
Update format of S3 client errors
This commit is contained in:
commit
9d281844cd
@ -3,6 +3,15 @@ from jinja2 import DictLoader, Environment
|
||||
from six import text_type
|
||||
|
||||
|
||||
SINGLE_ERROR_RESPONSE = u"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error>
|
||||
<Code>{{error_type}}</Code>
|
||||
<Message>{{message}}</Message>
|
||||
{% block extra %}{% endblock %}
|
||||
<RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
|
||||
</Error>
|
||||
"""
|
||||
|
||||
ERROR_RESPONSE = u"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Response>
|
||||
<Errors>
|
||||
@ -24,6 +33,7 @@ ERROR_JSON_RESPONSE = u"""{
|
||||
|
||||
class RESTError(HTTPException):
|
||||
templates = {
|
||||
'single_error': SINGLE_ERROR_RESPONSE,
|
||||
'error': ERROR_RESPONSE,
|
||||
'error_json': ERROR_JSON_RESPONSE,
|
||||
}
|
||||
|
@ -2,17 +2,20 @@ from __future__ import unicode_literals
|
||||
from moto.core.exceptions import RESTError
|
||||
|
||||
|
||||
ERROR_WITH_BUCKET_NAME = """{% extends 'error' %}
|
||||
ERROR_WITH_BUCKET_NAME = """{% extends 'single_error' %}
|
||||
{% block extra %}<BucketName>{{ bucket }}</BucketName>{% endblock %}
|
||||
"""
|
||||
|
||||
ERROR_WITH_KEY_NAME = """{% extends 'error' %}
|
||||
ERROR_WITH_KEY_NAME = """{% extends 'single_error' %}
|
||||
{% block extra %}<KeyName>{{ key_name }}</KeyName>{% endblock %}
|
||||
"""
|
||||
|
||||
|
||||
class S3ClientError(RESTError):
|
||||
pass
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('template', 'single_error')
|
||||
self.templates['bucket_error'] = ERROR_WITH_BUCKET_NAME
|
||||
super(S3ClientError, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class BucketError(S3ClientError):
|
||||
|
@ -1013,6 +1013,21 @@ def test_boto3_head_object():
|
||||
s3.Object('blah', 'hello2.txt').meta.client.head_object(Bucket='blah', Key='hello_bad.txt')
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_get_object():
|
||||
s3 = boto3.resource('s3', region_name='us-east-1')
|
||||
s3.create_bucket(Bucket="blah")
|
||||
|
||||
s3.Object('blah', 'hello.txt').put(Body="some text")
|
||||
|
||||
s3.Object('blah', 'hello.txt').meta.client.head_object(Bucket='blah', Key='hello.txt')
|
||||
|
||||
with assert_raises(ClientError) as e:
|
||||
s3.Object('blah', 'hello2.txt').get()
|
||||
|
||||
e.exception.response['Error']['Code'].should.equal('NoSuchKey')
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_boto3_head_object_with_versioning():
|
||||
s3 = boto3.resource('s3', region_name='us-east-1')
|
||||
|
Loading…
Reference in New Issue
Block a user