def test_get_entity_key(self): dd = DatastoreDistributed(None, None) item = Item(key_name="Bob", name="Bob", _app="hello") key = db.model_to_protobuf(item) self.assertEquals(str(dd.get_entity_key("howdy", key.key().path())), "howdy/Item:Bob!")
def test_delete_entities_txn(self): app = 'guestbook' txn_hash = {'root_key': 1} txn_str = '1'.zfill(ID_KEY_LENGTH) entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:]) db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) dd = DatastoreDistributed(db_batch, None) keys = [entity.key()] prefix = dd.get_table_prefix(entity.key()) entity_key = dd.get_entity_key(prefix, entity.key().path()) encoded_path = str( dd.encode_index_pb(entity.key().path())) txn_keys = [dd._SEPARATOR.join([app, txn_str, '', encoded_path])] txn_values = { txn_keys[0]: { dbconstants.TRANSACTIONS_SCHEMA[0]: dbconstants.TxnActions.DELETE, dbconstants.TRANSACTIONS_SCHEMA[1]: entity_key, dbconstants.TRANSACTIONS_SCHEMA[2]: '' } } flexmock(dd).should_receive('get_root_key').and_return('root_key') db_batch.should_receive('batch_put_entity').with_args( dbconstants.TRANSACTIONS_TABLE, txn_keys, dbconstants.TRANSACTIONS_SCHEMA, txn_values, ttl=TX_TIMEOUT * 2 ) dd.delete_entities_txn(app, keys, txn_hash)
def test_get_entity_key(self): db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) dd = DatastoreDistributed(db_batch, None) item = Item(key_name="Bob", name="Bob", _app="hello") key = db.model_to_protobuf(item) self.assertEquals(str(dd.get_entity_key("howdy", key.key().path())), "howdy\x00Item:Bob\x01")
def test_delete_entities_txn(self): app = 'guestbook' txn_hash = {'root_key': 1} txn_str = '1'.zfill(ID_KEY_LENGTH) entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:]) db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) dd = DatastoreDistributed(db_batch, None) keys = [entity.key()] prefix = dd.get_table_prefix(entity.key()) entity_key = dd.get_entity_key(prefix, entity.key().path()) encoded_path = str( dd._DatastoreDistributed__encode_index_pb(entity.key().path())) txn_keys = [dd._SEPARATOR.join([app, txn_str, '', encoded_path])] txn_values = { txn_keys[0]: { dbconstants.TRANSACTIONS_SCHEMA[0]: dbconstants.TxnActions.DELETE, dbconstants.TRANSACTIONS_SCHEMA[1]: entity_key, dbconstants.TRANSACTIONS_SCHEMA[2]: '' } } flexmock(dd).should_receive('get_root_key').and_return('root_key') db_batch.should_receive('batch_put_entity').with_args( dbconstants.TRANSACTIONS_TABLE, txn_keys, dbconstants.TRANSACTIONS_SCHEMA, txn_values, ttl=dd.MAX_TXN_DURATION * 2 ) dd.delete_entities_txn(app, keys, txn_hash)
def test_apply_txn_changes(self): app = 'guestbook' txn = 1 entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:]) db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) db_batch.should_receive('range_query').and_return([{ 'txn_entity_1': {'operation': dbconstants.TxnActions.PUT, 'operand': entity.Encode()} }]) db_batch.should_receive('get_indices').and_return([]) dd = DatastoreDistributed(db_batch, None) prefix = dd.get_table_prefix(entity) entity_key = dd.get_entity_key(prefix, entity.key().path()) db_batch.should_receive('batch_get_entity').and_return({entity_key: {}}) db_batch.should_receive('batch_mutate') dd.apply_txn_changes(app, txn)
def test_apply_txn_changes(self): app = 'guestbook' txn = 1 entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:]) db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) db_batch.should_receive('range_query').and_return([{ 'txn_entity_1': {'operation': dbconstants.TxnActions.PUT, 'operand': entity.Encode()} }]) flexmock(DatastoreDistributed).should_receive('get_indices').and_return([]) dd = DatastoreDistributed(db_batch, None) prefix = dd.get_table_prefix(entity) entity_key = dd.get_entity_key(prefix, entity.key().path()) db_batch.should_receive('batch_get_entity').and_return({entity_key: {}}) db_batch.should_receive('batch_mutate') dd.apply_txn_changes(app, txn)
def test_get_entity_key(self): dd = DatastoreDistributed(None) item = Item(key_name="Bob", name="Bob", _app="hello") key = db.model_to_protobuf(item) assert dd.get_entity_key("howdy", key.key().path()) == "howdy/Item:Bob!"
def test_get_entity_key(self): dd = DatastoreDistributed(None, None) item = Item(key_name="Bob", name="Bob", _app="hello") key = db.model_to_protobuf(item) self.assertEquals(str(dd.get_entity_key("howdy", key.key().path())), "howdy\x00Item:Bob!")