Support Python 3 using six
This commit is contained in:
parent
d653a3a3f7
commit
eedb4c4b73
67 changed files with 455 additions and 255 deletions
|
|
@ -14,46 +14,46 @@ def test_s3_server_get():
|
|||
|
||||
res = test_client.get('/')
|
||||
|
||||
res.data.should.contain('ListAllMyBucketsResult')
|
||||
res.data.should.contain(b'ListAllMyBucketsResult')
|
||||
|
||||
|
||||
def test_s3_server_bucket_create():
|
||||
backend = server.create_backend_app("s3bucket_path")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/foobar', 'http://localhost:5000')
|
||||
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.data.should.contain(b'<Name>foobar</Name>')
|
||||
|
||||
res = test_client.get('/foobar', 'http://localhost:5000')
|
||||
res = test_client.get('/foobar/', 'http://localhost:5000')
|
||||
res.status_code.should.equal(200)
|
||||
res.data.should.contain("ListBucketResult")
|
||||
res.data.should.contain(b"ListBucketResult")
|
||||
|
||||
res = test_client.get('/missing-bucket', 'http://localhost:5000')
|
||||
res = test_client.get('/missing-bucket/', 'http://localhost:5000')
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
res = test_client.put('/foobar/bar', 'http://localhost:5000', data='test value')
|
||||
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 = test_client.get('/foobar/bar/', 'http://localhost:5000')
|
||||
res.status_code.should.equal(200)
|
||||
res.data.should.equal("test value")
|
||||
res.data.should.equal(b"test value")
|
||||
|
||||
|
||||
def test_s3_server_post_to_bucket():
|
||||
backend = server.create_backend_app("s3bucket_path")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.put('/foobar2', 'http://localhost:5000/')
|
||||
res = test_client.put('/foobar2/', 'http://localhost:5000/')
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
test_client.post('/foobar2', "https://localhost:5000/", data={
|
||||
test_client.post('/foobar2/', "https://localhost:5000/", data={
|
||||
'key': 'the-key',
|
||||
'file': 'nothing'
|
||||
})
|
||||
|
||||
res = test_client.get('/foobar2/the-key', 'http://localhost:5000/')
|
||||
res = test_client.get('/foobar2/the-key/', 'http://localhost:5000/')
|
||||
res.status_code.should.equal(200)
|
||||
res.data.should.equal("nothing")
|
||||
res.data.should.equal(b"nothing")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
import urllib2
|
||||
from six.moves.urllib.request import urlopen
|
||||
from six.moves.urllib.error import HTTPError
|
||||
|
||||
import boto
|
||||
from boto.exception import S3ResponseError
|
||||
|
|
@ -41,7 +42,7 @@ def test_my_model_save():
|
|||
model_instance = MyModel('steve', 'is awesome')
|
||||
model_instance.save()
|
||||
|
||||
conn.get_bucket('mybucket').get_key('steve').get_contents_as_string().should.equal('is awesome')
|
||||
conn.get_bucket('mybucket').get_key('steve').get_contents_as_string().should.equal(b'is awesome')
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -56,7 +57,7 @@ def test_missing_key_urllib2():
|
|||
conn = create_connection('the_key', 'the_secret')
|
||||
conn.create_bucket("foobar")
|
||||
|
||||
urllib2.urlopen.when.called_with("http://s3.amazonaws.com/foobar/the-key").should.throw(urllib2.HTTPError)
|
||||
urlopen.when.called_with("http://s3.amazonaws.com/foobar/the-key").should.throw(HTTPError)
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -67,7 +68,7 @@ def test_empty_key():
|
|||
key.key = "the-key"
|
||||
key.set_contents_from_string("")
|
||||
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal('')
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal(b'')
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -78,10 +79,10 @@ 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('foobar')
|
||||
bucket.get_key("the-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('')
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal(b'')
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -92,7 +93,7 @@ def test_large_key_save():
|
|||
key.key = "the-key"
|
||||
key.set_contents_from_string("foobar" * 100000)
|
||||
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal('foobar' * 100000)
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal(b'foobar' * 100000)
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -105,8 +106,8 @@ def test_copy_key():
|
|||
|
||||
bucket.copy_key('new-key', 'foobar', 'the-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")
|
||||
bucket.get_key("the-key").get_contents_as_string().should.equal(b"some value")
|
||||
bucket.get_key("new-key").get_contents_as_string().should.equal(b"some value")
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -191,7 +192,7 @@ def test_post_to_bucket():
|
|||
'file': 'nothing'
|
||||
})
|
||||
|
||||
bucket.get_key('the-key').get_contents_as_string().should.equal('nothing')
|
||||
bucket.get_key('the-key').get_contents_as_string().should.equal(b'nothing')
|
||||
|
||||
|
||||
@mock_s3bucket_path
|
||||
|
|
@ -275,8 +276,8 @@ def test_bucket_key_listing_order():
|
|||
|
||||
delimiter = None
|
||||
keys = [x.name for x in bucket.list(prefix + 'x', delimiter)]
|
||||
keys.should.equal([u'toplevel/x/key', u'toplevel/x/y/key', u'toplevel/x/y/z/key'])
|
||||
keys.should.equal(['toplevel/x/key', 'toplevel/x/y/key', 'toplevel/x/y/z/key'])
|
||||
|
||||
delimiter = '/'
|
||||
keys = [x.name for x in bucket.list(prefix + 'x', delimiter)]
|
||||
keys.should.equal([u'toplevel/x/'])
|
||||
keys.should.equal(['toplevel/x/'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue