diff --git a/moto/s3/models.py b/moto/s3/models.py index 15d5fbe67..ef39fea69 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -11,12 +11,9 @@ class FakeKey(object): self.value = value self.last_modified = datetime.datetime.now() self._metadata = {} - + def set_metadata(self, key, metadata): self._metadata[key] = metadata - - def get_metadata(self, key): - return self._metadata[key] def append_to_value(self, value): self.value += value @@ -38,7 +35,7 @@ class FakeKey(object): # https://github.com/boto/boto/issues/466 RFC1123 = '%a, %d %b %Y %H:%M:%S GMT' return self.last_modified.strftime(RFC1123) - + @property def metadata(self): return self._metadata diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 1107c4189..5215d6409 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -101,7 +101,8 @@ def test_copy_key(): bucket.get_key("the-key").get_contents_as_string().should.equal("some value") bucket.get_key("new-key").get_contents_as_string().should.equal("some value") - + + @mock_s3 def test_set_metadata(): conn = boto.connect_s3('the_key', 'the_secret') @@ -113,6 +114,7 @@ def test_set_metadata(): bucket.get_key('the-key').get_metadata('md').should.equal('Metadatastring') + @freeze_time("2012-01-01 12:00:00") @mock_s3 def test_last_modified(): @@ -177,19 +179,20 @@ def test_get_all_buckets(): def test_post_to_bucket(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") - + requests.post("https://foobar.s3.amazonaws.com/", { 'key': 'the-key', 'file': 'nothing' }) bucket.get_key('the-key').get_contents_as_string().should.equal('nothing') - + + @mock_s3 def test_post_with_metadata_to_bucket(): conn = boto.connect_s3('the_key', 'the_secret') bucket = conn.create_bucket("foobar") - + requests.post("https://foobar.s3.amazonaws.com/", { 'key': 'the-key', 'file': 'nothing', @@ -198,6 +201,7 @@ def test_post_with_metadata_to_bucket(): bucket.get_key('the-key').get_metadata('test').should.equal('metadata') + @mock_s3 def test_bucket_method_not_implemented(): requests.patch.when.called_with("https://foobar.s3.amazonaws.com/").should.throw(NotImplementedError) diff --git a/tests/test_s3/test_server.py b/tests/test_s3/test_server.py index 0bfeb6efa..0ee507eae 100644 --- a/tests/test_s3/test_server.py +++ b/tests/test_s3/test_server.py @@ -33,3 +33,18 @@ def test_s3_server_bucket_create(): res = test_client.get('/bar', 'http://foobar.localhost:5000/') res.status_code.should.equal(200) res.data.should.equal("test value") + + +def test_s3_server_post_to_bucket(): + test_client = server.app.test_client() + res = test_client.put('/', 'http://foobar.localhost:5000/') + res.status_code.should.equal(200) + + test_client.post('/', "https://foobar.localhost:5000/", data={ + 'key': 'the-key', + 'file': 'nothing' + }) + + res = test_client.get('/the-key', 'http://foobar.localhost:5000/') + res.status_code.should.equal(200) + res.data.should.equal("nothing")