Beispiel #1
0
 def test_table_eq(self):
     """Tables should be equal"""
     field = DynamoKey("foo")
     a, b = Table("a", field), Table("a", field)
     self.assertEqual(a, b)
     self.assertEqual(hash(a), hash(b))
     self.assertFalse(a != b)
Beispiel #2
0
 def test_create_hash_table(self):
     """ Create a table with just a hash key """
     hash_key = DynamoKey('id', data_type=STRING)
     table = Table('foobar', hash_key)
     self.dynamo.create_table('foobar', hash_key=hash_key)
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
Beispiel #3
0
 def test_create_hash_range_table(self):
     """ Create a table with a hash and range key """
     hash_key = DynamoKey('id', data_type=STRING)
     range_key = DynamoKey('num', data_type=NUMBER)
     table = Table('foobar', hash_key, range_key)
     self.dynamo.create_table('foobar', hash_key, range_key)
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
Beispiel #4
0
 def test_create_table_throughput(self):
     """Create a table and set throughput"""
     hash_key = DynamoKey("id", data_type=STRING)
     throughput = Throughput(8, 2)
     table = Table("foobar", hash_key, throughput=throughput)
     self.dynamo.create_table("foobar", hash_key=hash_key, throughput=throughput)
     desc = self.dynamo.describe_table("foobar")
     self.assertEqual(desc, table)
Beispiel #5
0
 def test_create_global_keys_index(self):
     """ Create a table with a global KeysOnly index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.keys('name-index', index_field)
     table = Table('foobar', hash_key, global_indexes=[index])
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
Beispiel #6
0
 def test_create_global_index(self):
     """Create a table with a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     table = Table("foobar", hash_key, global_indexes=[index])
     self.dynamo.create_table("foobar", hash_key, global_indexes=[index])
     desc = self.dynamo.describe_table("foobar")
     self.assertEqual(desc, table)
Beispiel #7
0
 def test_create_global_hash_range_index(self):
     """ Create a global index with a hash and range key """
     hash_key = DynamoKey('id', data_type=STRING)
     index_hash = DynamoKey('foo')
     index_range = DynamoKey('bar')
     index = GlobalIndex.all('foo-index', index_hash, index_range)
     table = Table('foobar', hash_key, global_indexes=[index])
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
Beispiel #8
0
 def test_create_local_includes_index(self):
     """Create a table with a local Includes index"""
     hash_key = DynamoKey("id", data_type=STRING)
     range_key = DynamoKey("num", data_type=NUMBER)
     index_field = DynamoKey("name")
     index = LocalIndex.include("name-index", index_field, includes=["foo", "bar"])
     table = Table("foobar", hash_key, range_key, [index])
     self.dynamo.create_table("foobar", hash_key, range_key, indexes=[index])
     desc = self.dynamo.describe_table("foobar")
     self.assertEqual(desc, table)
Beispiel #9
0
 def test_create_global_index_throughput(self):
     """Create a table and set throughput on global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     throughput = Throughput(8, 2)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field, throughput=throughput)
     table = Table("foobar", hash_key, global_indexes=[index], throughput=throughput)
     self.dynamo.create_table(
         "foobar", hash_key=hash_key, global_indexes=[index], throughput=throughput
     )
     desc = self.dynamo.describe_table("foobar")
     self.assertEqual(desc, table)
Beispiel #10
0
 def test_create_local_index(self):
     """ Create a table with a local index """
     hash_key = DynamoKey('id', data_type=STRING)
     range_key = DynamoKey('num', data_type=NUMBER)
     index_field = DynamoKey('name')
     index = LocalIndex.all('name-index', index_field)
     table = Table('foobar', hash_key, range_key, [index])
     self.dynamo.create_table('foobar',
                              hash_key,
                              range_key,
                              indexes=[index])
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
Beispiel #11
0
 def from_description(cls, table: Table) -> "TableMeta":
     """Factory method that uses the dynamo3 'describe' return value"""
     attrs = {}
     for attr in table.attribute_definitions:
         field = TableField(attr.name, TYPES_REV[attr.data_type])
         attrs[field.name] = field
     for data in table.get("KeySchema", []):
         name = data["AttributeName"]
         attrs[name].key_type = data["KeyType"]
     for index in table.get("LocalSecondaryIndexes", []):
         for data in index["KeySchema"]:
             if data["KeyType"] == "RANGE":
                 name = data["AttributeName"]
                 index_type = index["Projection"]["ProjectionType"]
                 includes = index["Projection"].get("NonKeyAttributes")
                 attrs[name] = attrs[name].to_index(index_type,
                                                    index["IndexName"],
                                                    includes)
                 break
     global_indexes = {}
     for index in table.global_indexes:
         global_indexes[index.name] = GlobalIndexMeta(index)
     return cls(table, attrs, global_indexes)
Beispiel #12
0
 def test_describe_during_delete(self):
     """ Describing a table during a delete operation should not crash """
     response = {
         'ItemCount': 0,
         'ProvisionedThroughput': {
             'NumberOfDecreasesToday': 0,
             'ReadCapacityUnits': 5,
             'WriteCapacityUnits': 5
         },
         'TableName': 'myTableName',
         'TableSizeBytes': 0,
         'TableStatus': 'DELETING'
     }
     table = Table.from_response(response)
     self.assertEqual(table.status, 'DELETING')
Beispiel #13
0
 def test_describe_during_delete(self):
     """ Describing a table during a delete operation should not crash """
     response = {
         'ItemCount': 0,
         'ProvisionedThroughput': {
             'NumberOfDecreasesToday': 0,
             'ReadCapacityUnits': 5,
             'WriteCapacityUnits': 5
         },
         'TableName': 'myTableName',
         'TableSizeBytes': 0,
         'TableStatus': 'DELETING'
     }
     table = Table.from_response(response)
     self.assertEqual(table.status, 'DELETING')
Beispiel #14
0
 def test_describe_during_delete(self):
     """Describing a table during a delete operation should not crash"""
     response = {
         "ItemCount": 0,
         "ProvisionedThroughput": {
             "NumberOfDecreasesToday": 0,
             "ReadCapacityUnits": 5,
             "WriteCapacityUnits": 5,
         },
         "TableName": "myTableName",
         "TableSizeBytes": 0,
         "TableStatus": "DELETING",
     }
     table = Table.from_response(response)
     self.assertEqual(table.status, "DELETING")