From 8d6868f9d34501e56bb69aade0e293782f35ff3d Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Wed, 19 Nov 2014 21:06:23 -0500 Subject: [PATCH] For S3 Key Head requests, just return the real body for now so that key length works. Closes #131. --- moto/s3/responses.py | 2 +- tests/test_s3/test_s3.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index daa53d2da..aa5180abf 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -346,7 +346,7 @@ class ResponseObject(object): if key: headers.update(key.metadata) headers.update(key.response_dict) - return 200, headers, "" + return 200, headers, key.value else: return 404, headers, "" diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 894f04109..6f353e451 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -1,5 +1,4 @@ from __future__ import unicode_literals -import six from six.moves.urllib.request import urlopen from six.moves.urllib.error import HTTPError from io import BytesIO @@ -10,7 +9,7 @@ from boto.s3.connection import S3Connection from boto.s3.key import Key from freezegun import freeze_time import requests -import tests.backport_assert_raises +import tests.backport_assert_raises # noqa from nose.tools import assert_raises import sure # noqa @@ -187,7 +186,9 @@ def test_empty_key(): key.key = "the-key" key.set_contents_from_string("") - bucket.get_key("the-key").get_contents_as_string().should.equal(b'') + key = bucket.get_key("the-key") + key.size.should.equal(0) + key.get_contents_as_string().should.equal(b'') @mock_s3 @@ -198,7 +199,9 @@ def test_empty_key_set_on_existing_key(): key.key = "the-key" key.set_contents_from_string("foobar") - bucket.get_key("the-key").get_contents_as_string().should.equal(b'foobar') + key = bucket.get_key("the-key") + key.size.should.equal(6) + key.get_contents_as_string().should.equal(b'foobar') key.set_contents_from_string("") bucket.get_key("the-key").get_contents_as_string().should.equal(b'')