From 582db74deed584055e3b3ead2bb102c1c88a6bd8 Mon Sep 17 00:00:00 2001 From: Ian Auld Date: Thu, 14 Jan 2016 11:30:50 -0800 Subject: [PATCH] Added test for creating a table with a local index. --- .../test_dynamodb_table_with_range_key.py | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py index a90f06caf..a0a91d7f5 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py @@ -11,8 +11,9 @@ from moto import mock_dynamodb2 from boto.exception import JSONResponseError from tests.helpers import requires_boto_gte try: - from boto.dynamodb2.fields import GlobalAllIndex, HashKey, RangeKey + from boto.dynamodb2.fields import GlobalAllIndex, HashKey, RangeKey, AllIndex from boto.dynamodb2.table import Item, Table + from boto.dynamodb2.types import STRING from boto.dynamodb2.exceptions import ValidationException from boto.dynamodb2.exceptions import ConditionalCheckFailedException except ImportError: @@ -30,6 +31,30 @@ def create_table(): return table +def create_table_with_local_indexes(): + table = Table.create( + 'messages', + schema=[ + HashKey('forum_name'), + RangeKey('subject'), + ], + throughput={ + 'read': 10, + 'write': 10, + }, + indexes=[ + AllIndex( + 'recipient_timestamp_index', + parts=[ + HashKey('forum_name', data_type=STRING), + RangeKey('timestamp'), + ] + ) + ] + ) + return table + + def iterate_results(res): for i in res: pass @@ -63,6 +88,48 @@ def test_create_table(): table.describe().should.equal(expected) +@requires_boto_gte("2.9") +@mock_dynamodb2 +@freeze_time("2012-01-14") +def test_create_table(): + table = create_table_with_local_indexes() + expected = { + 'Table': { + 'AttributeDefinitions': [ + {'AttributeName': 'forum_name', 'AttributeType': 'S'}, + {'AttributeName': 'subject', 'AttributeType': 'S'}, + {'AttributeName': 'timestamp', 'AttributeType': 'S'} + ], + 'ProvisionedThroughput': { + 'NumberOfDecreasesToday': 0, + 'WriteCapacityUnits': 10, + 'ReadCapacityUnits': 10, + }, + 'TableSizeBytes': 0, + 'TableName': 'messages', + 'TableStatus': 'ACTIVE', + 'KeySchema': [ + {'KeyType': 'HASH', 'AttributeName': 'forum_name'}, + {'KeyType': 'RANGE', 'AttributeName': 'subject'} + ], + 'LocalSecondaryIndexes': [ + { + 'IndexName': 'recipient_timestamp_index', + 'KeySchema': [ + {'AttributeName': 'forum_name', 'KeyType': 'HASH'}, + {'AttributeName': 'timestamp', 'KeyType': 'RANGE'} + ], + 'Projection': {'ProjectionType': 'ALL'} + } + ], + 'ItemCount': 0, + 'CreationDateTime': 1326499200.0, + 'GlobalSecondaryIndexes': [], + } + } + table.describe().should.equal(expected) + + @requires_boto_gte("2.9") @mock_dynamodb2 def test_delete_table():