moto/tests/test_dynamodb/test_dynamodb.py

62 lines
1.7 KiB
Python
Raw Normal View History

import boto
2013-02-20 01:39:04 +00:00
from freezegun import freeze_time
from moto import mock_dynamodb
from moto.dynamodb import dynamodb_backend
2013-03-10 19:46:27 +00:00
from boto.exception import DynamoDBResponseError
@mock_dynamodb
2013-02-20 01:01:31 +00:00
def test_list_tables():
2013-02-20 01:39:04 +00:00
name = 'TestTable'
dynamodb_backend.create_table(name)
conn = boto.connect_dynamodb('the_key', 'the_secret')
assert conn.list_tables() == ['TestTable']
2013-02-20 01:39:04 +00:00
2013-03-10 19:46:27 +00:00
@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)
2013-02-20 01:39:04 +00:00
@freeze_time("2012-01-14")
@mock_dynamodb
def test_describe_table():
2013-03-05 13:35:18 +00:00
dynamodb_backend.create_table(
'messages',
2013-02-20 01:39:04 +00:00
hash_key_attr='forum_name',
hash_key_type='S',
range_key_attr='subject',
range_key_type='S',
read_capacity=10,
write_capacity=10,
)
conn = boto.connect_dynamodb('the_key', 'the_secret')
expected = {
2013-02-26 05:31:01 +00:00
'Table': {
'CreationDateTime': 1326499200.0,
'ItemCount': 0,
'KeySchema': {
'HashKeyElement': {
'AttributeName': 'forum_name',
'AttributeType': 'S'
},
'RangeKeyElement': {
'AttributeName': 'subject',
'AttributeType': 'S'
2013-02-20 01:39:04 +00:00
}
2013-02-26 05:31:01 +00:00
},
'ProvisionedThroughput': {
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
},
'TableName': 'messages',
'TableSizeBytes': 0,
'TableStatus': 'ACTIVE'
}
}
2013-02-20 01:39:04 +00:00
assert conn.describe_table('messages') == expected