Support Python 3 using six

This commit is contained in:
David Baumgold 2014-08-26 13:25:50 -04:00
commit eedb4c4b73
67 changed files with 455 additions and 255 deletions

View file

@ -1,7 +1,11 @@
from __future__ import unicode_literals
import six
import boto
import boto.dynamodb
import sure # noqa
import requests
import tests.backport_assert_raises
from nose.tools import assert_raises
from moto import mock_dynamodb
from moto.dynamodb import dynamodb_backend
@ -34,7 +38,8 @@ def test_list_tables_layer_1():
@mock_dynamodb
def test_describe_missing_table():
conn = boto.connect_dynamodb('the_key', 'the_secret')
conn.describe_table.when.called_with('messages').should.throw(DynamoDBResponseError)
with assert_raises(DynamoDBResponseError):
conn.describe_table('messages')
@mock_dynamodb

View file

@ -1,9 +1,11 @@
from __future__ import unicode_literals
import six
import boto
import sure # noqa
from freezegun import freeze_time
from moto import mock_dynamodb
from tests.helpers import py3_requires_boto_gte
from boto.dynamodb import condition
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError, DynamoDBValidationError
@ -27,6 +29,7 @@ def create_table(conn):
return table
@py3_requires_boto_gte("2.33.0")
@freeze_time("2012-01-14")
@mock_dynamodb
def test_create_table():
@ -59,6 +62,7 @@ def test_create_table():
conn.describe_table('messages').should.equal(expected)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_table():
conn = boto.connect_dynamodb()
@ -71,6 +75,7 @@ def test_delete_table():
conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_update_table_throughput():
conn = boto.connect_dynamodb()
@ -85,6 +90,7 @@ def test_update_table_throughput():
table.write_units.should.equal(6)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_item_add_and_describe_and_update():
conn = boto.connect_dynamodb()
@ -132,6 +138,7 @@ def test_item_add_and_describe_and_update():
})
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_item_put_without_table():
conn = boto.connect_dynamodb()
@ -145,6 +152,7 @@ def test_item_put_without_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_get_missing_item():
conn = boto.connect_dynamodb()
@ -157,6 +165,7 @@ def test_get_missing_item():
table.has_item("foobar", "more").should.equal(False)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_get_item_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -170,6 +179,7 @@ def test_get_item_with_undeclared_table():
).should.throw(DynamoDBKeyNotFoundError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_get_item_without_range_key():
conn = boto.connect_dynamodb()
@ -194,6 +204,7 @@ def test_get_item_without_range_key():
table.get_item.when.called_with(hash_key=hash_key).should.throw(DynamoDBValidationError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item():
conn = boto.connect_dynamodb()
@ -222,6 +233,7 @@ def test_delete_item():
item.delete.when.called_with().should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item_with_attribute_response():
conn = boto.connect_dynamodb()
@ -244,14 +256,14 @@ def test_delete_item_with_attribute_response():
response = item.delete(return_values='ALL_OLD')
response.should.equal({
u'Attributes': {
u'Body': u'http://url_to_lolcat.gif',
u'forum_name': u'LOLCat Forum',
u'ReceivedTime': u'12/9/2011 11:36:03 PM',
u'SentBy': u'User A',
u'subject': u'Check this out!'
'Attributes': {
'Body': 'http://url_to_lolcat.gif',
'forum_name': 'LOLCat Forum',
'ReceivedTime': '12/9/2011 11:36:03 PM',
'SentBy': 'User A',
'subject': 'Check this out!'
},
u'ConsumedCapacityUnits': 0.5
'ConsumedCapacityUnits': 0.5
})
table.refresh()
table.item_count.should.equal(0)
@ -259,6 +271,7 @@ def test_delete_item_with_attribute_response():
item.delete.when.called_with().should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -272,6 +285,7 @@ def test_delete_item_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_query():
conn = boto.connect_dynamodb()
@ -322,6 +336,7 @@ def test_query():
results.response['Items'].should.have.length_of(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_query_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -338,6 +353,7 @@ def test_query_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_scan():
conn = boto.connect_dynamodb()
@ -401,6 +417,7 @@ def test_scan():
results.response['Items'].should.have.length_of(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_scan_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -418,6 +435,7 @@ def test_scan_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_write_batch():
conn = boto.connect_dynamodb()
@ -462,6 +480,7 @@ def test_write_batch():
table.item_count.should.equal(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_batch_read():
conn = boto.connect_dynamodb()

View file

@ -1,9 +1,11 @@
from __future__ import unicode_literals
import six
import boto
import sure # noqa
from freezegun import freeze_time
from moto import mock_dynamodb
from tests.helpers import py3_requires_boto_gte
from boto.dynamodb import condition
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError
@ -25,6 +27,7 @@ def create_table(conn):
return table
@py3_requires_boto_gte("2.33.0")
@freeze_time("2012-01-14")
@mock_dynamodb
def test_create_table():
@ -53,6 +56,7 @@ def test_create_table():
conn.describe_table('messages').should.equal(expected)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_table():
conn = boto.connect_dynamodb()
@ -65,6 +69,7 @@ def test_delete_table():
conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_update_table_throughput():
conn = boto.connect_dynamodb()
@ -79,6 +84,7 @@ def test_update_table_throughput():
table.write_units.should.equal(6)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_item_add_and_describe_and_update():
conn = boto.connect_dynamodb()
@ -119,6 +125,7 @@ def test_item_add_and_describe_and_update():
})
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_item_put_without_table():
conn = boto.connect_dynamodb()
@ -131,6 +138,7 @@ def test_item_put_without_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_get_missing_item():
conn = boto.connect_dynamodb()
@ -141,6 +149,7 @@ def test_get_missing_item():
).should.throw(DynamoDBKeyNotFoundError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_get_item_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -153,6 +162,7 @@ def test_get_item_with_undeclared_table():
).should.throw(DynamoDBKeyNotFoundError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item():
conn = boto.connect_dynamodb()
@ -180,6 +190,7 @@ def test_delete_item():
item.delete.when.called_with().should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item_with_attribute_response():
conn = boto.connect_dynamodb()
@ -215,6 +226,7 @@ def test_delete_item_with_attribute_response():
item.delete.when.called_with().should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_delete_item_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -227,6 +239,7 @@ def test_delete_item_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_query():
conn = boto.connect_dynamodb()
@ -247,6 +260,7 @@ def test_query():
results.response['Items'].should.have.length_of(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_query_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -257,6 +271,7 @@ def test_query_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_scan():
conn = boto.connect_dynamodb()
@ -317,6 +332,7 @@ def test_scan():
results.response['Items'].should.have.length_of(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_scan_with_undeclared_table():
conn = boto.connect_dynamodb()
@ -334,6 +350,7 @@ def test_scan_with_undeclared_table():
).should.throw(DynamoDBResponseError)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_write_batch():
conn = boto.connect_dynamodb()
@ -376,6 +393,7 @@ def test_write_batch():
table.item_count.should.equal(1)
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb
def test_batch_read():
conn = boto.connect_dynamodb()

View file

@ -17,4 +17,4 @@ def test_table_list():
headers = {'X-Amz-Target': 'TestTable.ListTables'}
res = test_client.get('/', headers=headers)
res.data.should.contain('TableNames')
res.data.should.contain(b'TableNames')