moto/tests/test_s3bucket_path/test_bucket_path_server.py

62 lines
1.9 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
import sure # noqa
import moto.server as server
'''
Test the different server responses
'''
2015-11-27 13:49:44 -05:00
HEADERS = {'host': 's3.amazonaws.com'}
def test_s3_server_get():
2013-12-28 20:15:37 -05:00
backend = server.create_backend_app("s3bucket_path")
test_client = backend.test_client()
2015-11-27 13:49:44 -05:00
res = test_client.get('/', headers=HEADERS)
2014-08-26 13:25:50 -04:00
res.data.should.contain(b'ListAllMyBucketsResult')
def test_s3_server_bucket_create():
2013-12-28 20:15:37 -05:00
backend = server.create_backend_app("s3bucket_path")
test_client = backend.test_client()
2015-11-27 13:49:44 -05:00
res = test_client.put('/foobar/', 'http://localhost:5000', headers=HEADERS)
res.status_code.should.equal(200)
2015-11-27 13:49:44 -05:00
res = test_client.get('/', headers=HEADERS)
2014-08-26 13:25:50 -04:00
res.data.should.contain(b'<Name>foobar</Name>')
2015-11-27 13:49:44 -05:00
res = test_client.get('/foobar/', 'http://localhost:5000', headers=HEADERS)
res.status_code.should.equal(200)
2014-08-26 13:25:50 -04:00
res.data.should.contain(b"ListBucketResult")
2015-11-27 13:49:44 -05:00
res = test_client.get('/missing-bucket/', 'http://localhost:5000', headers=HEADERS)
2014-03-30 11:50:36 -04:00
res.status_code.should.equal(404)
2015-11-27 13:49:44 -05:00
res = test_client.put('/foobar/bar/', 'http://localhost:5000', data='test value', headers=HEADERS)
res.status_code.should.equal(200)
2015-11-27 13:49:44 -05:00
res = test_client.get('/foobar/bar/', 'http://localhost:5000', headers=HEADERS)
res.status_code.should.equal(200)
2014-08-26 13:25:50 -04:00
res.data.should.equal(b"test value")
def test_s3_server_post_to_bucket():
2013-12-28 20:15:37 -05:00
backend = server.create_backend_app("s3bucket_path")
test_client = backend.test_client()
2015-11-27 13:49:44 -05:00
res = test_client.put('/foobar2/', 'http://localhost:5000/', headers=HEADERS)
res.status_code.should.equal(200)
2014-08-26 13:25:50 -04:00
test_client.post('/foobar2/', "https://localhost:5000/", data={
'key': 'the-key',
'file': 'nothing'
2015-11-27 13:49:44 -05:00
}, headers=HEADERS)
2015-11-27 13:49:44 -05:00
res = test_client.get('/foobar2/the-key/', 'http://localhost:5000/', headers=HEADERS)
res.status_code.should.equal(200)
2014-08-26 13:25:50 -04:00
res.data.should.equal(b"nothing")