From 19d12d3bc33217290044ab5213a8497990cd827c Mon Sep 17 00:00:00 2001 From: John Lynn Date: Sun, 22 Feb 2015 22:13:34 +0700 Subject: [PATCH 1/2] Add failing test for bucket versioning --- tests/test_s3/test_server.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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() From 0496d4669e143f3bc492698b3969316ce6a773ea Mon Sep 17 00:00:00 2001 From: John Lynn Date: Sun, 22 Feb 2015 22:22:41 +0700 Subject: [PATCH 2/2] Fix bucket versioning when running under moto_server --- moto/s3/responses.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)