diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 143ad0214..a5f469812 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -137,8 +137,14 @@ class ResponseObject(_TemplateEnvironmentMixin): ) def _bucket_response_put(self, request, region_name, bucket_name, querystring, headers): + if hasattr(request, 'body'): + # Boto + body = request.body + else: + # Flask server + body = request.data if 'versioning' in querystring: - ver = re.search('([A-Za-z]+)', request.body.decode('utf-8')) + ver = re.search('([A-Za-z]+)', body.decode('utf-8')) if ver: self.backend.set_bucket_versioning(bucket_name, ver.group(1)) template = self.response_template(S3_BUCKET_VERSIONING) diff --git a/tests/test_s3/test_server.py b/tests/test_s3/test_server.py index 6acefd135..303224541 100644 --- a/tests/test_s3/test_server.py +++ b/tests/test_s3/test_server.py @@ -39,6 +39,16 @@ def test_s3_server_bucket_create(): res.data.should.equal(b"test value") +def test_s3_server_bucket_versioning(): + backend = server.create_backend_app("s3") + test_client = backend.test_client() + + # Just enough XML to enable versioning + body = 'Enabled' + res = test_client.put('/?versioning', 'http://foobaz.localhost:5000', data=body) + res.status_code.should.equal(200) + + def test_s3_server_post_to_bucket(): backend = server.create_backend_app("s3") test_client = backend.test_client()