def parse_select_type(cls, select, attributes_to_get, select_on_index=False): if select is None: if attributes_to_get: return SelectType.specific_attributes(attributes_to_get) else: if select_on_index: return SelectType.all_projected() else: return SelectType.all() if select == Values.SPECIFIC_ATTRIBUTES: assert attributes_to_get return SelectType.specific_attributes(attributes_to_get) assert not attributes_to_get if select == Values.ALL_ATTRIBUTES: return SelectType.all() if select == Values.ALL_PROJECTED_ATTRIBUTES: assert select_on_index return SelectType.all_projected() if select == Values.COUNT: return SelectType.count() assert False, "Select type wasn't recognized"
def parse_select_type(cls, select, attributes_to_get, select_on_index=False): if select is None: if attributes_to_get: return SelectType.specific_attributes( attributes_to_get ) else: if select_on_index: return SelectType.all_projected() else: return SelectType.all() if select == Values.SPECIFIC_ATTRIBUTES: assert attributes_to_get return SelectType.specific_attributes(attributes_to_get) assert not attributes_to_get if select == Values.ALL_ATTRIBUTES: return SelectType.all() if select == Values.ALL_PROJECTED_ATTRIBUTES: assert select_on_index return SelectType.all_projected() if select == Values.COUNT: return SelectType.count() assert False, "Select type wasn't recognized"
def test_select_item_count(self): self.storage_mocker.StubOutWithMock(storage, 'select_item') storage.select_item( IgnoreArg(), IgnoreArg(), IgnoreArg(), select_type=SelectType.count(), index_name=IgnoreArg(), limit=IgnoreArg(), exclusive_start_key=IgnoreArg(), consistent=IgnoreArg(), order_type=IgnoreArg() ).AndReturn( models.SelectResult( count=100500 ) ) self.storage_mocker.ReplayAll() table = Table('test_table', connection=self.DYNAMODB_CON) count = table.query_count(consistent=False, hash_key__eq=1) self.assertEqual(count, 100500) self.storage_mocker.VerifyAll()
def test_select_item_count(self): self.storage_mocker.StubOutWithMock(storage, 'select_item') storage.select_item(IgnoreArg(), IgnoreArg(), IgnoreArg(), select_type=SelectType.count(), index_name=IgnoreArg(), limit=IgnoreArg(), exclusive_start_key=IgnoreArg(), consistent=IgnoreArg(), order_type=IgnoreArg()).AndReturn( models.SelectResult(count=100500)) self.storage_mocker.ReplayAll() table = Table('test_table', connection=self.DYNAMODB_CON) count = table.query_count(consistent=False, hash_key__eq=1) self.assertEqual(count, 100500) self.storage_mocker.VerifyAll()