S3 Mock should return an HTTP 409 if trying to create a bucket that
already exists. Closes #94.
This commit is contained in:
parent
76553671f2
commit
60cd79c6e2
6 changed files with 33 additions and 16 deletions
2
moto/s3/exceptions.py
Normal file
2
moto/s3/exceptions.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
class BucketAlreadyExists(Exception):
|
||||
pass
|
||||
|
|
@ -5,10 +5,11 @@ import hashlib
|
|||
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import iso_8601_datetime, rfc_1123_datetime
|
||||
from .exceptions import BucketAlreadyExists
|
||||
from .utils import clean_key_name
|
||||
|
||||
UPLOAD_ID_BYTES=43
|
||||
UPLOAD_PART_MIN_SIZE=5242880
|
||||
UPLOAD_ID_BYTES = 43
|
||||
UPLOAD_PART_MIN_SIZE = 5242880
|
||||
|
||||
|
||||
class FakeKey(object):
|
||||
|
|
@ -107,6 +108,8 @@ class S3Backend(BaseBackend):
|
|||
self.buckets = {}
|
||||
|
||||
def create_bucket(self, bucket_name):
|
||||
if bucket_name in self.buckets:
|
||||
raise BucketAlreadyExists()
|
||||
new_bucket = FakeBucket(name=bucket_name)
|
||||
self.buckets[bucket_name] = new_bucket
|
||||
return new_bucket
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import re
|
|||
|
||||
from jinja2 import Template
|
||||
|
||||
from .exceptions import BucketAlreadyExists
|
||||
from .models import s3_backend
|
||||
from .utils import bucket_name_from_url
|
||||
|
||||
|
|
@ -66,7 +67,10 @@ class ResponseObject(object):
|
|||
else:
|
||||
return 404, headers, ""
|
||||
elif method == 'PUT':
|
||||
new_bucket = self.backend.create_bucket(bucket_name)
|
||||
try:
|
||||
new_bucket = self.backend.create_bucket(bucket_name)
|
||||
except BucketAlreadyExists:
|
||||
return 409, headers, ""
|
||||
template = Template(S3_BUCKET_CREATE_RESPONSE)
|
||||
return template.render(bucket=new_bucket)
|
||||
elif method == 'DELETE':
|
||||
|
|
@ -148,7 +152,7 @@ class ResponseObject(object):
|
|||
upload_id=upload_id,
|
||||
count=len(parts),
|
||||
parts=parts
|
||||
)
|
||||
)
|
||||
key = self.backend.get_key(bucket_name, key_name)
|
||||
if key:
|
||||
headers.update(key.metadata)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue