Updating dynamodb2 tests for newer boto.

This commit is contained in:
Steve Pulec 2014-07-22 21:47:56 -04:00
parent 415291d11a
commit 12d61ede41
3 changed files with 138 additions and 138 deletions

View File

@ -4,13 +4,10 @@ python:
- 2.7 - 2.7
env: env:
matrix: matrix:
- BOTO_VERSION==2.31.1
- BOTO_VERSION=2.25.0 - BOTO_VERSION=2.25.0
- BOTO_VERSION=2.19.0 - BOTO_VERSION=2.19.0
- BOTO_VERSION=2.12.0 - BOTO_VERSION=2.12.0
- BOTO_VERSION=2.11.0
- BOTO_VERSION=2.10.0
- BOTO_VERSION=2.9.9
- BOTO_VERSION=2.8
- BOTO_VERSION=2.7 - BOTO_VERSION=2.7
install: install:
- pip install boto==$BOTO_VERSION - pip install boto==$BOTO_VERSION

View File

@ -9,11 +9,10 @@ try:
from boto.dynamodb2.fields import RangeKey from boto.dynamodb2.fields import RangeKey
from boto.dynamodb2.table import Table from boto.dynamodb2.table import Table
from boto.dynamodb2.table import Item from boto.dynamodb2.table import Item
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError
from boto.dynamodb2.exceptions import ValidationException from boto.dynamodb2.exceptions import ValidationException
from boto.dynamodb2.exceptions import ConditionalCheckFailedException
except ImportError: except ImportError:
print "This boto version is not supported" pass
def create_table(): def create_table():
table = Table.create('messages', schema=[ table = Table.create('messages', schema=[
@ -25,10 +24,10 @@ def create_table():
}) })
return table return table
def iterate_results(res): def iterate_results(res):
for i in res: for i in res:
print i pass
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@ -208,13 +207,12 @@ def test_delete_item():
response.should.equal(True) response.should.equal(True)
table.count().should.equal(0) table.count().should.equal(0)
item.delete.when.called_with().should.throw(ConditionalCheckFailedException) item.delete().should.equal(False)
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@mock_dynamodb2 @mock_dynamodb2
def test_delete_item_with_undeclared_table(): def test_delete_item_with_undeclared_table():
conn = boto.connect_dynamodb()
table = Table("undeclared-table") table = Table("undeclared-table")
item_data = { item_data = {
'forum_name': 'LOLCat Forum', 'forum_name': 'LOLCat Forum',
@ -430,14 +428,18 @@ def test_batch_read():
item_data['forum_name'] = 'another-key' item_data['forum_name'] = 'another-key'
item_data['subject'] = '789' item_data['subject'] = '789'
item.save() item.save()
results = table.batch_get(keys=[ results = table.batch_get(
keys=[
{'forum_name': 'the-key', 'subject': '123'}, {'forum_name': 'the-key', 'subject': '123'},
{'forum_name': 'another-key', 'subject': '789'}]) {'forum_name': 'another-key', 'subject': '789'},
]
)
# Iterate through so that batch_item gets called # Iterate through so that batch_item gets called
count = len([x for x in results]) count = len([x for x in results])
count.should.equal(2) count.should.equal(2)
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@mock_dynamodb2 @mock_dynamodb2
def test_get_key_fields(): def test_get_key_fields():

View File

@ -6,11 +6,11 @@ from moto import mock_dynamodb2
from tests.helpers import requires_boto_gte from tests.helpers import requires_boto_gte
try: try:
from boto.dynamodb2.fields import HashKey from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.fields import RangeKey
from boto.dynamodb2.table import Table from boto.dynamodb2.table import Table
from boto.dynamodb2.table import Item from boto.dynamodb2.table import Item
except ImportError: except ImportError:
print "This boto version is not supported" pass
def create_table(): def create_table():
table = Table.create('messages', schema=[ table = Table.create('messages', schema=[
@ -22,12 +22,11 @@ def create_table():
return table return table
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@mock_dynamodb2 @mock_dynamodb2
@freeze_time("2012-01-14") @freeze_time("2012-01-14")
def test_create_table(): def test_create_table():
table = create_table() create_table()
expected = { expected = {
'Table': { 'Table': {
'AttributeDefinitions': [ 'AttributeDefinitions': [
@ -48,7 +47,8 @@ def test_create_table():
conn = boto.dynamodb2.connect_to_region( conn = boto.dynamodb2.connect_to_region(
'us-west-2', 'us-west-2',
aws_access_key_id="ak", aws_access_key_id="ak",
aws_secret_access_key="sk") aws_secret_access_key="sk"
)
conn.describe_table('messages').should.equal(expected) conn.describe_table('messages').should.equal(expected)
@ -78,7 +78,6 @@ def test_update_table_throughput():
'write': 6, 'write': 6,
}) })
table.throughput["read"].should.equal(5) table.throughput["read"].should.equal(5)
table.throughput["write"].should.equal(6) table.throughput["write"].should.equal(6)
@ -172,7 +171,7 @@ def test_delete_item():
table.count().should.equal(0) table.count().should.equal(0)
item.delete.when.called_with().should.throw(JSONResponseError) item.delete().should.equal(False)
@requires_boto_gte("2.9") @requires_boto_gte("2.9")
@ -346,9 +345,12 @@ def test_batch_read():
item_data['forum_name'] = 'another-key' item_data['forum_name'] = 'another-key'
item.save(overwrite=True) item.save(overwrite=True)
results = table.batch_get(keys=[ results = table.batch_get(
keys=[
{'forum_name': 'the-key1'}, {'forum_name': 'the-key1'},
{'forum_name': 'another-key'}]) {'forum_name': 'another-key'},
]
)
# Iterate through so that batch_item gets called # Iterate through so that batch_item gets called
count = len([x for x in results]) count = len([x for x in results])
@ -380,4 +382,3 @@ def test_get_special_item():
table.put_item(data=data) table.put_item(data=data)
returned_item = table.get_item(**{'date-joined': 127549192}) returned_item = table.get_item(**{'date-joined': 127549192})
dict(returned_item).should.equal(data) dict(returned_item).should.equal(data)