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)
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)
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"])
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)
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)
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)
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)
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)
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)
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)
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)
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)
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')
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)
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)
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')
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])
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" )
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])
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])
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])
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)
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])
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])
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])
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)
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)