2013-10-28 20:43:25 +00:00
|
|
|
import sure # noqa
|
|
|
|
|
|
|
|
import moto.server as server
|
|
|
|
|
|
|
|
'''
|
|
|
|
Test the different server responses
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
def test_s3_server_get():
|
2013-12-29 01:15:37 +00:00
|
|
|
backend = server.create_backend_app("s3bucket_path")
|
|
|
|
test_client = backend.test_client()
|
|
|
|
|
2013-10-28 20:43:25 +00:00
|
|
|
res = test_client.get('/')
|
|
|
|
|
|
|
|
res.data.should.contain('ListAllMyBucketsResult')
|
|
|
|
|
|
|
|
|
|
|
|
def test_s3_server_bucket_create():
|
2013-12-29 01:15:37 +00:00
|
|
|
backend = server.create_backend_app("s3bucket_path")
|
|
|
|
test_client = backend.test_client()
|
|
|
|
|
2013-10-28 20:43:25 +00:00
|
|
|
res = test_client.put('/foobar', 'http://localhost:5000')
|
|
|
|
res.status_code.should.equal(200)
|
|
|
|
|
|
|
|
res = test_client.get('/')
|
|
|
|
res.data.should.contain('<Name>foobar</Name>')
|
|
|
|
|
|
|
|
res = test_client.get('/foobar', 'http://localhost:5000')
|
|
|
|
res.status_code.should.equal(200)
|
|
|
|
res.data.should.contain("ListBucketResult")
|
|
|
|
|
|
|
|
res = test_client.put('/foobar/bar', 'http://localhost:5000', data='test value')
|
|
|
|
res.status_code.should.equal(200)
|
|
|
|
|
|
|
|
res = test_client.get('/foobar/bar', 'http://localhost:5000')
|
|
|
|
res.status_code.should.equal(200)
|
|
|
|
res.data.should.equal("test value")
|
|
|
|
|
|
|
|
|
|
|
|
def test_s3_server_post_to_bucket():
|
2013-12-29 01:15:37 +00:00
|
|
|
backend = server.create_backend_app("s3bucket_path")
|
|
|
|
test_client = backend.test_client()
|
|
|
|
|
2014-03-17 01:25:14 +00:00
|
|
|
res = test_client.put('/foobar2', 'http://localhost:5000/')
|
2013-10-28 20:43:25 +00:00
|
|
|
res.status_code.should.equal(200)
|
|
|
|
|
2014-03-17 01:25:14 +00:00
|
|
|
test_client.post('/foobar2', "https://localhost:5000/", data={
|
2013-10-28 20:43:25 +00:00
|
|
|
'key': 'the-key',
|
|
|
|
'file': 'nothing'
|
|
|
|
})
|
|
|
|
|
2014-03-17 01:25:14 +00:00
|
|
|
res = test_client.get('/foobar2/the-key', 'http://localhost:5000/')
|
2013-10-28 20:43:25 +00:00
|
|
|
res.status_code.should.equal(200)
|
|
|
|
res.data.should.equal("nothing")
|