示例#1
0
 def test_global_index_eq(self):
     """Global indexes should be equal"""
     hash_key = DynamoKey("foo")
     a, b = GlobalIndex.all("a", hash_key), GlobalIndex.all("a", hash_key)
     self.assertEqual(a, b)
     self.assertEqual(hash(a), hash(b))
     self.assertFalse(a != b)
示例#2
0
 def test_global_index_eq(self):
     """ Global indexes should be equal """
     hash_key = DynamoKey('foo')
     a, b = GlobalIndex.all('a', hash_key), GlobalIndex.all('a', hash_key)
     self.assertEqual(a, b)
     self.assertEqual(hash(a), hash(b))
     self.assertFalse(a != b)
示例#3
0
 def test_magic_index_props(self):
     """Index can look up properties on response object"""
     index = GlobalIndex.all("idx-name", DynamoKey("id"))
     index.response = {"FooBar": 2}
     self.assertEqual(index["FooBar"], 2)
     with self.assertRaises(KeyError):
         self.assertIsNotNone(index["Missing"])
示例#4
0
 def test_magic_index_props(self):
     """ Index magically looks up properties on response object """
     index = GlobalIndex.all('idx-name', DynamoKey('id'))
     index.response = {'FooBar': 2}
     self.assertEqual(index.foo_bar, 2)
     with self.assertRaises(AttributeError):
         self.assertIsNotNone(index.crazy_property)
示例#5
0
 def test_magic_index_props(self):
     """ Index magically looks up properties on response object """
     index = GlobalIndex.all('idx-name', DynamoKey('id'))
     index.response = {
         'FooBar': 2
     }
     self.assertEqual(index.foo_bar, 2)
     with self.assertRaises(AttributeError):
         self.assertIsNotNone(index.crazy_property)
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
0
 def test_create_index(self):
     """ Create a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     self.dynamo.create_table('foobar', hash_key=hash_key)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field, hash_key)
     self.dynamo.update_table('foobar', index_updates=[
         IndexUpdate.create(index)])
     table = self.dynamo.describe_table('foobar')
     self.assertEqual(len(table.global_indexes), 1)
示例#11
0
 def test_create_index(self):
     """Create a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     self.dynamo.create_table("foobar", hash_key=hash_key)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field, hash_key)
     self.dynamo.update_table("foobar", index_updates=[IndexUpdate.create(index)])
     table = self.dynamo.describe_table("foobar")
     assert table is not None
     self.assertEqual(len(table.global_indexes), 1)
示例#12
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)
示例#13
0
 def test_create_index(self):
     """ Create a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     self.dynamo.create_table('foobar', hash_key=hash_key)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field, hash_key)
     self.dynamo.update_table('foobar',
                              index_updates=[IndexUpdate.create(index)])
     table = self.dynamo.describe_table('foobar')
     self.assertEqual(len(table.global_indexes), 1)
示例#14
0
 def test_update_global_index_throughput_old(self):
     """ Update throughput on a global index OLD API """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key=hash_key,
                              global_indexes=[index])
     tp = Throughput(2, 1)
     self.dynamo.update_table('foobar', global_indexes={'name-index': tp})
     table = self.dynamo.describe_table('foobar')
     self.assertEqual(table.global_indexes[0].throughput, tp)
示例#15
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])
     self.dynamo.create_table(
         'foobar', hash_key=hash_key, global_indexes=[index])
     desc = self.dynamo.describe_table('foobar')
     self.assertEqual(desc, table)
示例#16
0
 def test_update_global_index_throughput_old(self):
     """ Update throughput on a global index OLD API """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar',
                              hash_key=hash_key,
                              global_indexes=[index])
     tp = Throughput(2, 1)
     self.dynamo.update_table('foobar', global_indexes={'name-index': tp})
     table = self.dynamo.describe_table('foobar')
     self.assertEqual(table.global_indexes[0].throughput, tp)
示例#17
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)
示例#18
0
 def test_delete_index(self):
     """ Delete a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key=hash_key,
                              global_indexes=[index])
     self.dynamo.update_table('foobar', index_updates=[
         IndexUpdate.delete('name-index')])
     table = self.dynamo.describe_table('foobar')
     self.assertTrue(len(table.global_indexes) == 0 or
                     table.global_indexes[0].index_status == 'DELETING')
示例#19
0
 def test_update_index_throughput(self):
     """Update the throughput on a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     self.dynamo.create_table("foobar", hash_key=hash_key, global_indexes=[index])
     tp = Throughput(2, 1)
     self.dynamo.update_table(
         "foobar", index_updates=[IndexUpdate.update("name-index", tp)]
     )
     table = self.dynamo.describe_table("foobar")
     assert table is not None
     self.assertEqual(table.global_indexes[0].throughput, tp)
示例#20
0
 def test_delete_index(self):
     """ Delete a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar',
                              hash_key=hash_key,
                              global_indexes=[index])
     self.dynamo.update_table(
         'foobar', index_updates=[IndexUpdate.delete('name-index')])
     table = self.dynamo.describe_table('foobar')
     self.assertTrue(
         len(table.global_indexes) == 0
         or table.global_indexes[0].index_status == 'DELETING')
示例#21
0
 def test_global_index(self):
     """ Can query on a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
     item = {
         'id': 'a',
         'name': 'baz',
     }
     self.dynamo.put_item('foobar', item)
     ret = self.dynamo.query('foobar', id__eq='a', name__eq='baz',
                             index='name-index')
     self.assertItemsEqual(list(ret), [item])
示例#22
0
 def test_global_index(self):
     """ Can query on a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
     item = {
         'id': 'a',
         'name': 'baz',
     }
     self.dynamo.put_item('foobar', item)
     ret = self.dynamo.query('foobar', name__eq='baz',
                             index='name-index',
                             filter={'id__eq': 'a'})
     self.assertItemsEqual(list(ret), [item])
示例#23
0
 def test_delete_index(self):
     """Delete a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     self.dynamo.create_table("foobar", hash_key=hash_key, global_indexes=[index])
     self.dynamo.update_table(
         "foobar", index_updates=[IndexUpdate.delete("name-index")]
     )
     table = self.dynamo.describe_table("foobar")
     assert table is not None
     self.assertTrue(
         len(table.global_indexes) == 0
         or table.global_indexes[0].status == "DELETING"
     )
示例#24
0
 def test_scan_index(self):
     """Can scan a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     self.dynamo.create_table("foobar", hash_key, global_indexes=[index])
     item = {
         "id": "a",
         "name": "baz",
     }
     self.dynamo.put_item("foobar", item)
     item2 = {
         "id": "b",
     }
     self.dynamo.put_item("foobar", item2)
     ret = self.dynamo.scan("foobar", index="name-index")
     self.assertCountEqual(list(ret), [item])
示例#25
0
 def test_scan_index(self):
     """ Can scan a global index """
     hash_key = DynamoKey('id', data_type=STRING)
     index_field = DynamoKey('name')
     index = GlobalIndex.all('name-index', index_field)
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
     item = {
         'id': 'a',
         'name': 'baz',
     }
     self.dynamo.put_item('foobar', item)
     item2 = {
         'id': 'b',
     }
     self.dynamo.put_item('foobar', item2)
     ret = self.dynamo.scan2('foobar', index='name-index')
     self.assertItemsEqual(list(ret), [item])
示例#26
0
 def test_update_multiple_throughputs(self):
     """Update table and global index throughputs"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field, throughput=(2, 3))
     self.dynamo.create_table(
         "foobar",
         hash_key=hash_key,
         global_indexes=[index],
         throughput=Throughput(1, 1),
     )
     tp = Throughput(3, 4)
     self.dynamo.update_table(
         "foobar",
         throughput=tp,
         index_updates=[IndexUpdate.update("name-index", tp)],
     )
     table = self.dynamo.describe_table("foobar")
     assert table is not None
     self.assertEqual(table.throughput, tp)
     self.assertEqual(table.global_indexes[0].throughput, tp)
示例#27
0
 def test_global_index(self):
     """Can query on a global index"""
     hash_key = DynamoKey("id", data_type=STRING)
     index_field = DynamoKey("name")
     index = GlobalIndex.all("name-index", index_field)
     self.dynamo.create_table("foobar", hash_key, global_indexes=[index])
     item = {
         "id": "a",
         "name": "baz",
     }
     self.dynamo.put_item("foobar", item)
     ret = self.dynamo.query(
         "foobar",
         "#name = :name",
         alias={"#name": "name"},
         index="name-index",
         filter="id = :id",
         id="a",
         name="baz",
     )
     self.assertCountEqual(list(ret), [item])
示例#28
0
 def setUp(self):
     super(TestRateLimit, self).setUp()
     hash_key = DynamoKey("id")
     index_key = DynamoKey("bar")
     index = GlobalIndex.all("bar", index_key)
     self.dynamo.create_table("foobar", hash_key, global_indexes=[index])
示例#29
0
 def setUp(self):
     super(TestRateLimit, self).setUp()
     hash_key = DynamoKey('id')
     index_key = DynamoKey('bar')
     index = GlobalIndex.all('bar', index_key)
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
示例#30
0
 def setUp(self):
     super(TestRateLimit, self).setUp()
     hash_key = DynamoKey('id')
     index_key = DynamoKey('bar')
     index = GlobalIndex.all('bar', index_key)
     self.dynamo.create_table('foobar', hash_key, global_indexes=[index])
示例#31
0
 def test_global_local_ne(self):
     """Global indexes should not equal local indexes"""
     field = DynamoKey("foo")
     a, b = LocalIndex.all("a", field), GlobalIndex.all("a", field, field)
     self.assertNotEqual(a, b)
示例#32
0
 def test_global_local_ne(self):
     """ Global indexes should not equal local indexes """
     field = DynamoKey('foo')
     a, b = LocalIndex.all('a', field), GlobalIndex.all('a', field, field)
     self.assertNotEqual(a, b)