This commit is contained in:
Steve Pulec 2017-02-23 21:37:43 -05:00
commit f37bad0e00
260 changed files with 6363 additions and 3766 deletions

View file

@ -15,17 +15,18 @@ try:
except ImportError:
print("This boto version is not supported")
@requires_boto_gte("2.9")
@mock_dynamodb2_deprecated
def test_list_tables():
name = 'TestTable'
#{'schema': }
dynamodb_backend2.create_table(name,schema=[
dynamodb_backend2.create_table(name, schema=[
{u'KeyType': u'HASH', u'AttributeName': u'forum_name'},
{u'KeyType': u'RANGE', u'AttributeName': u'subject'}
])
conn = boto.dynamodb2.connect_to_region(
'us-west-2',
conn = boto.dynamodb2.connect_to_region(
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
assert conn.list_tables()["TableNames"] == [name]
@ -34,13 +35,13 @@ def test_list_tables():
@requires_boto_gte("2.9")
@mock_dynamodb2_deprecated
def test_list_tables_layer_1():
dynamodb_backend2.create_table("test_1",schema=[
dynamodb_backend2.create_table("test_1", schema=[
{u'KeyType': u'HASH', u'AttributeName': u'name'}
])
dynamodb_backend2.create_table("test_2",schema=[
dynamodb_backend2.create_table("test_2", schema=[
{u'KeyType': u'HASH', u'AttributeName': u'name'}
])
conn = boto.dynamodb2.connect_to_region(
conn = boto.dynamodb2.connect_to_region(
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
@ -57,7 +58,7 @@ def test_list_tables_layer_1():
@requires_boto_gte("2.9")
@mock_dynamodb2_deprecated
def test_describe_missing_table():
conn = boto.dynamodb2.connect_to_region(
conn = boto.dynamodb2.connect_to_region(
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")

View file

@ -140,7 +140,8 @@ def test_delete_table():
table.delete()
conn.list_tables()["TableNames"].should.have.length_of(0)
conn.delete_table.when.called_with('messages').should.throw(JSONResponseError)
conn.delete_table.when.called_with(
'messages').should.throw(JSONResponseError)
@requires_boto_gte("2.9")
@ -181,7 +182,8 @@ def test_item_add_and_describe_and_update():
})
ok.should.equal(True)
table.get_item(forum_name="LOLCat Forum", subject='Check this out!').should_not.be.none
table.get_item(forum_name="LOLCat Forum",
subject='Check this out!').should_not.be.none
returned_item = table.get_item(
forum_name='LOLCat Forum',
@ -224,7 +226,8 @@ def test_item_partial_save():
}
table.put_item(data=data)
returned_item = table.get_item(forum_name="LOLCat Forum", subject='The LOLz')
returned_item = table.get_item(
forum_name="LOLCat Forum", subject='The LOLz')
returned_item['SentBy'] = 'User B'
returned_item.partial_save()
@ -270,7 +273,8 @@ def test_get_missing_item():
@mock_dynamodb2_deprecated
def test_get_item_with_undeclared_table():
table = Table('undeclared-table')
table.get_item.when.called_with(test_hash=3241526475).should.throw(JSONResponseError)
table.get_item.when.called_with(
test_hash=3241526475).should.throw(JSONResponseError)
@requires_boto_gte("2.9")
@ -287,7 +291,8 @@ def test_get_item_without_range_key():
hash_key = 3241526475
range_key = 1234567890987
table.put_item(data={'test_hash': hash_key, 'test_range': range_key})
table.get_item.when.called_with(test_hash=hash_key).should.throw(ValidationException)
table.get_item.when.called_with(
test_hash=hash_key).should.throw(ValidationException)
@requires_boto_gte("2.30.0")
@ -355,19 +360,23 @@ def test_query():
table.count().should.equal(4)
results = table.query_2(forum_name__eq='the-key', subject__gt='1', consistent=True)
results = table.query_2(forum_name__eq='the-key',
subject__gt='1', consistent=True)
expected = ["123", "456", "789"]
for index, item in enumerate(results):
item["subject"].should.equal(expected[index])
results = table.query_2(forum_name__eq="the-key", subject__gt='1', reverse=True)
results = table.query_2(forum_name__eq="the-key",
subject__gt='1', reverse=True)
for index, item in enumerate(results):
item["subject"].should.equal(expected[len(expected) - 1 - index])
results = table.query_2(forum_name__eq='the-key', subject__gt='1', consistent=True)
results = table.query_2(forum_name__eq='the-key',
subject__gt='1', consistent=True)
sum(1 for _ in results).should.equal(3)
results = table.query_2(forum_name__eq='the-key', subject__gt='234', consistent=True)
results = table.query_2(forum_name__eq='the-key',
subject__gt='234', consistent=True)
sum(1 for _ in results).should.equal(2)
results = table.query_2(forum_name__eq='the-key', subject__gt='9999')
@ -379,7 +388,8 @@ def test_query():
results = table.query_2(forum_name__eq='the-key', subject__beginswith='7')
sum(1 for _ in results).should.equal(1)
results = table.query_2(forum_name__eq='the-key', subject__between=['567', '890'])
results = table.query_2(forum_name__eq='the-key',
subject__between=['567', '890'])
sum(1 for _ in results).should.equal(1)
@ -558,15 +568,15 @@ def test_create_with_global_indexes():
RangeKey('version'),
], global_indexes=[
GlobalAllIndex('topic-created_at-index',
parts=[
HashKey('topic'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 6,
'write': 1
}
),
parts=[
HashKey('topic'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 6,
'write': 1
}
),
])
table_description = conn.describe_table("messages")
@ -601,25 +611,25 @@ def test_query_with_global_indexes():
RangeKey('version'),
], global_indexes=[
GlobalAllIndex('topic-created_at-index',
parts=[
HashKey('topic'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 6,
'write': 1
}
),
parts=[
HashKey('topic'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 6,
'write': 1
}
),
GlobalAllIndex('status-created_at-index',
parts=[
HashKey('status'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 2,
'write': 1
}
)
parts=[
HashKey('status'),
RangeKey('created_at', data_type='N')
],
throughput={
'read': 2,
'write': 1
}
)
])
item_data = {
@ -653,7 +663,8 @@ def test_query_with_local_indexes():
item['version'] = '2'
item.save(overwrite=True)
results = table.query(forum_name__eq='Cool Forum', index='threads_index', threads__eq=1)
results = table.query(forum_name__eq='Cool Forum',
index='threads_index', threads__eq=1)
list(results).should.have.length_of(1)
@ -888,7 +899,8 @@ def test_failed_overwrite():
table.put_item(data=data2, overwrite=True)
data3 = {'id': '123', 'range': 'abc', 'data': '812'}
table.put_item.when.called_with(data=data3).should.throw(ConditionalCheckFailedException)
table.put_item.when.called_with(data=data3).should.throw(
ConditionalCheckFailedException)
returned_item = table.lookup('123', 'abc')
dict(returned_item).should.equal(data2)
@ -972,7 +984,8 @@ def test_boto3_conditions():
# Test a query returning all items
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").gt('1'),
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").gt('1'),
ScanIndexForward=True,
)
expected = ["123", "456", "789"]
@ -981,7 +994,8 @@ def test_boto3_conditions():
# Return all items again, but in reverse
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").gt('1'),
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").gt('1'),
ScanIndexForward=False,
)
for index, item in enumerate(reversed(results['Items'])):
@ -989,29 +1003,34 @@ def test_boto3_conditions():
# Filter the subjects to only return some of the results
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").gt('234'),
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").gt('234'),
ConsistentRead=True,
)
results['Count'].should.equal(2)
# Filter to return no results
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").gt('9999')
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").gt('9999')
)
results['Count'].should.equal(0)
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").begins_with('12')
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").begins_with('12')
)
results['Count'].should.equal(1)
results = table.query(
KeyConditionExpression=Key("subject").begins_with('7') & Key('forum_name').eq('the-key')
KeyConditionExpression=Key("subject").begins_with(
'7') & Key('forum_name').eq('the-key')
)
results['Count'].should.equal(1)
results = table.query(
KeyConditionExpression=Key('forum_name').eq('the-key') & Key("subject").between('567', '890')
KeyConditionExpression=Key('forum_name').eq(
'the-key') & Key("subject").between('567', '890')
)
results['Count'].should.equal(1)
@ -1337,7 +1356,8 @@ def test_boto3_query_gsi_range_comparison():
# Test a query returning all johndoe items
results = table.query(
KeyConditionExpression=Key('username').eq('johndoe') & Key("created").gt(0),
KeyConditionExpression=Key('username').eq(
'johndoe') & Key("created").gt(0),
ScanIndexForward=True,
IndexName='TestGSI',
)
@ -1347,7 +1367,8 @@ def test_boto3_query_gsi_range_comparison():
# Return all johndoe items again, but in reverse
results = table.query(
KeyConditionExpression=Key('username').eq('johndoe') & Key("created").gt(0),
KeyConditionExpression=Key('username').eq(
'johndoe') & Key("created").gt(0),
ScanIndexForward=False,
IndexName='TestGSI',
)
@ -1357,7 +1378,8 @@ def test_boto3_query_gsi_range_comparison():
# Filter the creation to only return some of the results
# And reverse order of hash + range key
results = table.query(
KeyConditionExpression=Key("created").gt(1) & Key('username').eq('johndoe'),
KeyConditionExpression=Key("created").gt(
1) & Key('username').eq('johndoe'),
ConsistentRead=True,
IndexName='TestGSI',
)
@ -1365,20 +1387,23 @@ def test_boto3_query_gsi_range_comparison():
# Filter to return no results
results = table.query(
KeyConditionExpression=Key('username').eq('janedoe') & Key("created").gt(9),
KeyConditionExpression=Key('username').eq(
'janedoe') & Key("created").gt(9),
IndexName='TestGSI',
)
results['Count'].should.equal(0)
results = table.query(
KeyConditionExpression=Key('username').eq('janedoe') & Key("created").eq(5),
KeyConditionExpression=Key('username').eq(
'janedoe') & Key("created").eq(5),
IndexName='TestGSI',
)
results['Count'].should.equal(1)
# Test range key sorting
results = table.query(
KeyConditionExpression=Key('username').eq('johndoe') & Key("created").gt(0),
KeyConditionExpression=Key('username').eq(
'johndoe') & Key("created").gt(0),
IndexName='TestGSI',
)
expected = [Decimal('1'), Decimal('2'), Decimal('3')]
@ -1516,7 +1541,6 @@ def test_boto3_update_table_gsi_throughput():
gsi_throughput['WriteCapacityUnits'].should.equal(11)
@mock_dynamodb2
def test_update_table_gsi_create():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')

View file

@ -71,7 +71,8 @@ def test_delete_table():
conn.delete_table('messages')
conn.list_tables()["TableNames"].should.have.length_of(0)
conn.delete_table.when.called_with('messages').should.throw(JSONResponseError)
conn.delete_table.when.called_with(
'messages').should.throw(JSONResponseError)
@requires_boto_gte("2.9")
@ -239,7 +240,8 @@ def test_query_with_undeclared_table():
conn.query.when.called_with(
table_name='undeclared-table',
key_conditions={"forum_name": {"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "the-key"}]}}
key_conditions={"forum_name": {
"ComparisonOperator": "EQ", "AttributeValueList": [{"S": "the-key"}]}}
).should.throw(JSONResponseError)
@ -396,7 +398,8 @@ def test_get_key_fields():
@mock_dynamodb2_deprecated
def test_get_missing_item():
table = create_table()
table.get_item.when.called_with(forum_name='missing').should.throw(ItemNotFound)
table.get_item.when.called_with(
forum_name='missing').should.throw(ItemNotFound)
@requires_boto_gte("2.9")
@ -436,7 +439,8 @@ def test_update_item_remove():
}
# Then remove the SentBy field
conn.update_item("messages", key_map, update_expression="REMOVE SentBy, SentTo")
conn.update_item("messages", key_map,
update_expression="REMOVE SentBy, SentTo")
returned_item = table.get_item(username="steve")
dict(returned_item).should.equal({
@ -460,7 +464,8 @@ def test_update_item_set():
'username': {"S": "steve"}
}
conn.update_item("messages", key_map, update_expression="SET foo=bar, blah=baz REMOVE SentBy")
conn.update_item("messages", key_map,
update_expression="SET foo=bar, blah=baz REMOVE SentBy")
returned_item = table.get_item(username="steve")
dict(returned_item).should.equal({
@ -470,7 +475,6 @@ def test_update_item_set():
})
@mock_dynamodb2_deprecated
def test_failed_overwrite():
table = Table.create('messages', schema=[
@ -487,7 +491,8 @@ def test_failed_overwrite():
table.put_item(data=data2, overwrite=True)
data3 = {'id': '123', 'data': '812'}
table.put_item.when.called_with(data=data3).should.throw(ConditionalCheckFailedException)
table.put_item.when.called_with(data=data3).should.throw(
ConditionalCheckFailedException)
returned_item = table.lookup('123')
dict(returned_item).should.equal(data2)
@ -521,6 +526,7 @@ def test_conflicting_writes():
boto3
"""
@mock_dynamodb2
def test_boto3_create_table():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
@ -617,7 +623,6 @@ def test_boto3_put_item_conditions_pass():
assert dict(returned_item)['Item']['foo'].should.equal("baz")
@mock_dynamodb2
def test_scan_pagination():
table = _create_user_table()