summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Lindsley <daniel@toastdriven.com>2013-12-16 17:25:42 -0800
committerDaniel Lindsley <daniel@toastdriven.com>2013-12-17 16:44:14 -0800
commitd1fc813dd5b3854736769427eab9f80409fc6e7e (patch)
treef2b12c90f8672fc614b393eb36adbaa2052078e5 /tests
parentb33c549115ab6e17ca312eb4899f822181f473c4 (diff)
downloadboto-d1fc813dd5b3854736769427eab9f80409fc6e7e.tar.gz
Revised the GSI work a bit.
This still needs more tests (especially integration ones) & to have the ``Table.update`` method updated as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/dynamodb2/test_table.py131
1 files changed, 130 insertions, 1 deletions
diff --git a/tests/unit/dynamodb2/test_table.py b/tests/unit/dynamodb2/test_table.py
index 16b62fd8..b761c8b4 100644
--- a/tests/unit/dynamodb2/test_table.py
+++ b/tests/unit/dynamodb2/test_table.py
@@ -2,7 +2,9 @@ import mock
import unittest
from boto.dynamodb2 import exceptions
from boto.dynamodb2.fields import (HashKey, RangeKey,
- AllIndex, KeysOnlyIndex, IncludeIndex)
+ AllIndex, KeysOnlyIndex, IncludeIndex,
+ GlobalAllIndex, GlobalKeysOnlyIndex,
+ GlobalIncludeIndex)
from boto.dynamodb2.items import Item
from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.results import ResultSet, BatchGetResultSet
@@ -169,6 +171,133 @@ class IndexFieldTestCase(unittest.TestCase):
}
})
+ def test_global_all_index(self):
+ all_index = GlobalAllIndex('AllKeys', parts=[
+ HashKey('username'),
+ RangeKey('date_joined')
+ ],
+ throughput={
+ 'read': 6,
+ 'write': 2,
+ })
+ self.assertEqual(all_index.name, 'AllKeys')
+ self.assertEqual([part.attr_type for part in all_index.parts], [
+ 'HASH',
+ 'RANGE'
+ ])
+ self.assertEqual(all_index.projection_type, 'ALL')
+
+ self.assertEqual(all_index.definition(), [
+ {'AttributeName': 'username', 'AttributeType': 'S'},
+ {'AttributeName': 'date_joined', 'AttributeType': 'S'}
+ ])
+ self.assertEqual(all_index.schema(), {
+ 'IndexName': 'AllKeys',
+ 'KeySchema': [
+ {
+ 'AttributeName': 'username',
+ 'KeyType': 'HASH'
+ },
+ {
+ 'AttributeName': 'date_joined',
+ 'KeyType': 'RANGE'
+ }
+ ],
+ 'Projection': {
+ 'ProjectionType': 'ALL'
+ },
+ 'ProvisionedThroughput': {
+ 'ReadCapacityUnits': 6,
+ 'WriteCapacityUnits': 2
+ }
+ })
+
+ def test_global_keys_only_index(self):
+ keys_only = GlobalKeysOnlyIndex('KeysOnly', parts=[
+ HashKey('username'),
+ RangeKey('date_joined')
+ ],
+ throughput={
+ 'read': 3,
+ 'write': 4,
+ })
+ self.assertEqual(keys_only.name, 'KeysOnly')
+ self.assertEqual([part.attr_type for part in keys_only.parts], [
+ 'HASH',
+ 'RANGE'
+ ])
+ self.assertEqual(keys_only.projection_type, 'KEYS_ONLY')
+
+ self.assertEqual(keys_only.definition(), [
+ {'AttributeName': 'username', 'AttributeType': 'S'},
+ {'AttributeName': 'date_joined', 'AttributeType': 'S'}
+ ])
+ self.assertEqual(keys_only.schema(), {
+ 'IndexName': 'KeysOnly',
+ 'KeySchema': [
+ {
+ 'AttributeName': 'username',
+ 'KeyType': 'HASH'
+ },
+ {
+ 'AttributeName': 'date_joined',
+ 'KeyType': 'RANGE'
+ }
+ ],
+ 'Projection': {
+ 'ProjectionType': 'KEYS_ONLY'
+ },
+ 'ProvisionedThroughput': {
+ 'ReadCapacityUnits': 3,
+ 'WriteCapacityUnits': 4
+ }
+ })
+
+ def test_global_include_index(self):
+ # Lean on the default throughput
+ include_index = GlobalIncludeIndex('IncludeKeys', parts=[
+ HashKey('username'),
+ RangeKey('date_joined')
+ ], includes=[
+ 'gender',
+ 'friend_count'
+ ])
+ self.assertEqual(include_index.name, 'IncludeKeys')
+ self.assertEqual([part.attr_type for part in include_index.parts], [
+ 'HASH',
+ 'RANGE'
+ ])
+ self.assertEqual(include_index.projection_type, 'INCLUDE')
+
+ self.assertEqual(include_index.definition(), [
+ {'AttributeName': 'username', 'AttributeType': 'S'},
+ {'AttributeName': 'date_joined', 'AttributeType': 'S'}
+ ])
+ self.assertEqual(include_index.schema(), {
+ 'IndexName': 'IncludeKeys',
+ 'KeySchema': [
+ {
+ 'AttributeName': 'username',
+ 'KeyType': 'HASH'
+ },
+ {
+ 'AttributeName': 'date_joined',
+ 'KeyType': 'RANGE'
+ }
+ ],
+ 'Projection': {
+ 'ProjectionType': 'INCLUDE',
+ 'NonKeyAttributes': [
+ 'gender',
+ 'friend_count',
+ ]
+ },
+ 'ProvisionedThroughput': {
+ 'ReadCapacityUnits': 5,
+ 'WriteCapacityUnits': 5
+ }
+ })
+
class ItemTestCase(unittest.TestCase):
def setUp(self):