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,4 +1,6 @@
from __future__ import unicode_literals
from __future__ import unicode_literals, print_function
import six
import boto
import sure # noqa
import requests
@ -6,10 +8,12 @@ from moto import mock_dynamodb2
from moto.dynamodb2 import dynamodb_backend2
from boto.exception import JSONResponseError
from tests.helpers import requires_boto_gte
import tests.backport_assert_raises
from nose.tools import assert_raises
try:
import boto.dynamodb2
except ImportError:
print "This boto version is not supported"
print("This boto version is not supported")
@requires_boto_gte("2.9")
@mock_dynamodb2
@ -57,7 +61,8 @@ def test_describe_missing_table():
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
conn.describe_table.when.called_with('messages').should.throw(JSONResponseError)
with assert_raises(JSONResponseError):
conn.describe_table('messages')
@requires_boto_gte("2.9")

View file

@ -1,10 +1,11 @@
from __future__ import unicode_literals
import six
import boto
import sure # noqa
from freezegun import freeze_time
from moto import mock_dynamodb2
from boto.exception import JSONResponseError
from tests.helpers import requires_boto_gte
from tests.helpers import requires_boto_gte, py3_requires_boto_gte
try:
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.fields import RangeKey
@ -32,6 +33,7 @@ def iterate_results(res):
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
@freeze_time("2012-01-14")
def test_create_table():
@ -59,6 +61,7 @@ def test_create_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -71,6 +74,7 @@ def test_delete_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_update_table_throughput():
table = create_table()
@ -96,6 +100,7 @@ def test_update_table_throughput():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_item_add_and_describe_and_update():
table = create_table()
@ -139,9 +144,9 @@ def test_item_add_and_describe_and_update():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_item_put_without_table():
table = Table('undeclared-table')
item_data = {
'forum_name': 'LOLCat Forum',
@ -154,9 +159,9 @@ def test_item_put_without_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_missing_item():
table = create_table()
table.get_item.when.called_with(
@ -166,6 +171,7 @@ def test_get_missing_item():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_item_with_undeclared_table():
table = Table('undeclared-table')
@ -173,6 +179,7 @@ def test_get_item_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_item_without_range_key():
table = Table.create('messages', schema=[
@ -190,6 +197,7 @@ def test_get_item_without_range_key():
@requires_boto_gte("2.30.0")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_item():
table = create_table()
@ -212,6 +220,7 @@ def test_delete_item():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_item_with_undeclared_table():
table = Table("undeclared-table")
@ -226,9 +235,9 @@ def test_delete_item_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_query():
table = create_table()
item_data = {
@ -284,6 +293,7 @@ def test_query():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_query_with_undeclared_table():
table = Table('undeclared')
@ -296,6 +306,7 @@ def test_query_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_scan():
table = create_table()
@ -351,6 +362,7 @@ def test_scan():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_scan_with_undeclared_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -368,6 +380,7 @@ def test_scan_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_write_batch():
table = create_table()
@ -398,6 +411,7 @@ def test_write_batch():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_batch_read():
table = create_table()
@ -442,6 +456,7 @@ def test_batch_read():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_key_fields():
table = create_table()

View file

@ -1,10 +1,11 @@
from __future__ import unicode_literals
import six
import boto
import sure # noqa
from freezegun import freeze_time
from boto.exception import JSONResponseError
from moto import mock_dynamodb2
from tests.helpers import requires_boto_gte
from tests.helpers import requires_boto_gte, py3_requires_boto_gte
try:
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.table import Table
@ -24,6 +25,7 @@ def create_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
@freeze_time("2012-01-14")
def test_create_table():
@ -55,6 +57,7 @@ def test_create_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_table():
create_table()
@ -68,6 +71,7 @@ def test_delete_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_update_table_throughput():
table = create_table()
@ -84,6 +88,7 @@ def test_update_table_throughput():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_item_add_and_describe_and_update():
table = create_table()
@ -118,6 +123,7 @@ def test_item_add_and_describe_and_update():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_item_put_without_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -133,6 +139,7 @@ def test_item_put_without_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_missing_item():
table = create_table()
@ -141,6 +148,7 @@ def test_get_missing_item():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_item_with_undeclared_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -152,6 +160,7 @@ def test_get_item_with_undeclared_table():
@requires_boto_gte("2.30.0")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_item():
table = create_table()
@ -176,6 +185,7 @@ def test_delete_item():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_delete_item_with_undeclared_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -187,6 +197,7 @@ def test_delete_item_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_query():
table = create_table()
@ -207,6 +218,7 @@ def test_query():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_query_with_undeclared_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -218,6 +230,7 @@ def test_query_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_scan():
table = create_table()
@ -269,6 +282,7 @@ def test_scan():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_scan_with_undeclared_table():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
@ -287,6 +301,7 @@ def test_scan_with_undeclared_table():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_write_batch():
table = create_table()
@ -318,6 +333,7 @@ def test_write_batch():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_batch_read():
table = create_table()
@ -359,6 +375,7 @@ def test_batch_read():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_key_fields():
table = create_table()
@ -367,6 +384,7 @@ def test_get_key_fields():
@requires_boto_gte("2.9")
@py3_requires_boto_gte("2.33.0")
@mock_dynamodb2
def test_get_special_item():
table = Table.create('messages', schema=[

View file

@ -16,4 +16,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')