def test_query_async(self): connection = OrientSocket( 'localhost', 2424 ) open_msg = DbOpenMessage(connection) open_msg.set_db_name('GratefulDeadConcerts')\ .set_user('admin').set_pass('admin').prepare()\ .send().fetch_response() def _test_callback(record): assert record is not [] assert record._rid is not None # assert no exception try_select_async = CommandMessage(connection) try_select_async.set_command_type(QUERY_ASYNC)\ .set_query("select from followed_by")\ .set_limit(50)\ .set_fetch_plan("*:0")\ .set_callback( _test_callback )\ .prepare()\ response = try_select_async.send().fetch_response() assert response is None
def test_shutdown(self): import inspect print("# WARNING comment return below this line " \ "to test this message. Line %u" % \ inspect.currentframe().f_back.f_lineno) return connection = OrientSocket("localhost", 2424) msg = ConnectMessage(connection) print("%r" % msg.get_protocol()) assert msg.get_protocol() != -1 sid = msg.prepare( ("admin", "admin") )\ .send().fetch_response() """ alternative use session_id = msg.set_user("admin").set_pass("admin").prepare()\ .send().fetch_response() """ print("%r" % sid) assert sid != -1 shut_msg = ShutdownMessage(connection) res = shut_msg.prepare(("root", "16ABC88EB0CAEE3774E00BABB6D19E69FD3495D6BFA32CAF8AD95A64DA7415CE")).\ send().send().fetch_response() assert res[:] == []
def test_db_open_connected(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) print("%r" % conn_msg.get_protocol()) assert conn_msg.get_protocol() != -1 session_id = conn_msg.prepare( ("admin", "admin") )\ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() print("Cluster: %s" % cluster_info) assert len(cluster_info) != 0
def test_gremlin(self): connection = OrientSocket("localhost", 2424) print("Sid, should be -1 : %s" % connection.session_id) assert connection.session_id == -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(cluster_info) != 0 req_msg = CommandMessage(connection) res = req_msg.prepare( [ QUERY_GREMLIN, "g.V.outE('followed_by')[0]" ] ) \ .send().fetch_response() assert len(res) == 1 assert res[0]._rid == '#11:0' assert res[0]._class == 'followed_by' assert res[0]._version == 1 print("%r" % res[0]._rid) print("%r" % res[0]._class) print("%r" % res[0]._version)
def test_record_load(self): connection = OrientSocket("localhost", 2424) assert connection.session_id == -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(cluster_info) != 0 def _test_callback(record): assert record is not [] assert record.rid is not None # assert no exception req_msg = RecordLoadMessage(connection) res = req_msg.prepare( [ "#11:0", "*:-1", _test_callback ] ) \ .send().fetch_response() assert res.rid == "#11:0" assert res.o_class == 'followed_by' assert res._in != 0 assert res._out != 0
def test_db_exists(self): connection = OrientSocket("localhost", 2424) msg = ConnectMessage(connection) print("%r" % msg.get_protocol()) assert msg.get_protocol() != -1 session_id = msg.prepare( ("admin", "admin") )\ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 db_name = "GratefulDeadConcerts" # params = ( db_name, STORAGE_TYPE_MEMORY ) params = (db_name, STORAGE_TYPE_PLOCAL) msg = DbExistsMessage(connection) exists = msg.prepare(params).send().fetch_response() assert exists is True msg.close() print("%r" % exists)
def test_db_create_without_connect(self): connection = OrientSocket("localhost", 2424) with self.assertRaises(PyOrientConnectionException): (DbCreateMessage(connection)).prepare( ("db_test", DB_TYPE_DOCUMENT, STORAGE_TYPE_PLOCAL)).send().fetch_response()
def test_attach_class_hint(self): try: connection = OrientSocket("localhost", 2424) tx = TxCommitMessage(connection) tx.begin() tx.attach([1, 2, 3]) assert False # should not happens except AssertionError as e: assert 'A subclass of BaseMessage was expected' == str(e) assert True
def test_private_fetch(self): try: connection = OrientSocket("localhost", 2424) DbOpenMessage( connection )\ .prepare( ("GratefulDeadConcerts", "admin", "admin", DB_TYPE_DOCUMENT, "") ).send().fetch_response() tx = TxCommitMessage(connection) tx.begin() tx.fetch_response() assert False except AttributeError as e: print(str(e)) assert True
def test_wrong_data_range(self): connection = OrientSocket('localhost', 2424) db_name = "GratefulDeadConcerts" db = DbOpenMessage(connection) cluster_info = db.prepare((db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() datarange = DataClusterDataRangeMessage(connection) try: value = datarange.prepare(32767).send().fetch_response() except PyOrientCommandException as e: print(repr(str(e))) assert "java.lang.ArrayIndexOutOfBoundsException" in str(e)
def test_db_create_with_drop(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) print("Protocol: %r" % conn_msg.get_protocol()) assert connection.protocol != -1 session_id = conn_msg.prepare( ("admin", "admin") ) \ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 # ################## db_name = "my_little_test" msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() print("Before %r" % exists) assert exists is True # should happen every time because of latest test if exists is True: ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() print("Creation again") try: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_DOCUMENT, STORAGE_TYPE_PLOCAL)).send().fetch_response() assert True except PyOrientCommandException as e: print(str(e)) assert False # No expected Exception msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() assert exists is True # at the end drop the test database ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() msg.close() print("After %r" % exists)
def test_db_list(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) print("%r" % conn_msg.get_protocol()) assert conn_msg.get_protocol() != -1 session_id = conn_msg.prepare( ("root", "root") )\ .send().fetch_response() reload_msg = DbListMessage(connection) _list = reload_msg.prepare().send().fetch_response() print("Database List: %s" % _list.oRecordData['databases']) assert len(_list.oRecordData['databases']) != 0
def test_db_close(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) print("Protocol: %r" % conn_msg.get_protocol()) assert connection.protocol != -1 session_id = conn_msg.prepare( ("admin", "admin") ) \ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 c_msg = DbCloseMessage(connection) closing = c_msg.prepare(None)\ .send().fetch_response() assert closing is 0
def test_db_open_not_connected(self): connection = OrientSocket("localhost", 2424) print("Sid, should be -1 : %s" % connection.session_id) assert connection.session_id == -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" _, clusters, _ = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(clusters) != 0 return connection, clusters
def test_data_cluster_count(self): connection = OrientSocket( "localhost", 2424 ) assert connection.session_id == -1 # ################## msg = DbOpenMessage( connection ) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "") ).send().fetch_response() print(cluster_info) assert len(cluster_info) != 0 assert connection.session_id != -1 count_msg = DataClusterCountMessage( connection ) res1 = count_msg.set_count_tombstones(1)\ .prepare( [ (0,1,2,3,4,5) ] ).send().fetch_response() assert res1 is not 0 assert res1 > 0 count_msg = DataClusterCountMessage( connection ) res2 = count_msg.set_count_tombstones(1)\ .prepare( [ (0,1,2,3,4,5), 1 ] ).send().fetch_response() assert res2 is not 0 assert res2 > 0 count_msg = DataClusterCountMessage( connection ) res3 = count_msg.set_count_tombstones(1).set_cluster_ids( (0,1,2,3,4,5) )\ .prepare().send().fetch_response() assert res3 is not 0 assert res3 > 0 assert res1 == res2 assert res3 == res2 assert res3 == res1
def test_data_range(self): connection = OrientSocket('localhost', 2424) db_name = "GratefulDeadConcerts" db = DbOpenMessage(connection) cluster_info = db.prepare((db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() cluster_info.sort(key=lambda cluster: cluster['id']) for cluster in cluster_info: # os.environ['DEBUG'] = '0' # silence debug datarange = DataClusterDataRangeMessage(connection) value = datarange.prepare(cluster['id']).send().fetch_response() print("Cluster Name: %s, ID: %u: %s " \ % ( cluster['name'], cluster['id'], value )) assert value is not [] assert value is not None
def test_connection(self): connection = OrientSocket("localhost", 2424) msg = ConnectMessage(connection) print("%r" % msg.get_protocol()) assert msg.get_protocol() != -1 session_id = msg.prepare( ("admin", "admin") )\ .send().fetch_response() """ alternative use session_id = msg.set_user("admin").set_pass("admin").prepare()\ .send().fetch_response() """ assert session_id == connection.session_id assert session_id != -1 msg.close() print("%r" % msg._header) print("%r" % session_id)
def test_record_count_with_no_opened_db(self): connection = OrientSocket("localhost", 2424) assert connection.session_id == -1 # ################## conn_msg = ConnectMessage(connection) session_id = conn_msg.prepare( ("admin", "admin") )\ .send().fetch_response() assert session_id == connection.session_id assert session_id != -1 try: count_msg = DbCountRecordsMessage(connection) res = count_msg.prepare().send().fetch_response() assert False # we expect an exception because we need a db opened except PyOrientDatabaseException: assert True
def test_db_create_with_connect(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) print("Protocol: %r" % conn_msg.get_protocol()) session_id = conn_msg.prepare(("root", "root")) \ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 # ################## db_name = "my_little_test" response = '' try: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_DOCUMENT, STORAGE_TYPE_PLOCAL) ).send().fetch_response() except PyOrientDatabaseException as e: assert True print(str(e)) except Exception as e: print(str(e)) assert False print("Creation: %r" % response) assert len(response) == 0 msg = DbExistsMessage(connection) msg.prepare((db_name, STORAGE_TYPE_PLOCAL)) # msg.prepare( [db_name] ) exists = msg.send().fetch_response() assert exists is True msg.close() print("%r" % exists)
def test_record_count(self): connection = OrientSocket("localhost", 2424) assert connection.session_id == -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(cluster_info) != 0 session_id = connection.session_id assert session_id != -1 count_msg = DbCountRecordsMessage(connection) res = count_msg.prepare().send().fetch_response() assert res is not 0 assert res > 0
def test_command(self): connection = OrientSocket("localhost", 2424) print("Sid, should be -1 : %s" % connection.session_id) assert connection.session_id == -1 # ################## msg = DbOpenMessage(connection) db_name = "GratefulDeadConcerts" cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(cluster_info) != 0 req_msg = CommandMessage(connection) res = req_msg.prepare( [ QUERY_SYNC, "select * from followed_by limit 1" ] ) \ .send().fetch_response() print("%r" % res[0].rid) print("%r" % res[0].o_class) print("%r" % res[0].version)
def test_data_cluster_add_drop(self): import random connection = OrientSocket('localhost', 2424) db_name = 'GratefulDeadConcerts' db_open = DbOpenMessage(connection) clusters = db_open.prepare( ( db_name, 'admin', 'admin' ) ) \ .send().fetch_response() _created_clusters = [] for _rng in range(0, 5): data_cadd = DataClusterAddMessage(connection) new_cluster_id = data_cadd.prepare([ 'my_cluster_' + str(random.randint(0, 999999999)), CLUSTER_TYPE_PHYSICAL # 'PHYSICAL' ]).send().fetch_response() _created_clusters.append(new_cluster_id) print("New cluster ID: %u" % new_cluster_id) os.environ['DEBUG'] = '0' # silence debug _reload = DbReloadMessage(connection) new_cluster_list = _reload.prepare().send().fetch_response() new_cluster_list.dataClusters.sort(key=lambda cluster: cluster['id']) _list = [] for cluster in new_cluster_list: datarange = DataClusterDataRangeMessage(connection) value = datarange.prepare(cluster['id']).send().fetch_response() print("Cluster Name: %s, ID: %u: %s " \ % ( cluster['name'], cluster['id'], value )) _list.append(cluster['id']) assert value is not [] assert value is not None # check for new cluster in database try: for _cl in _created_clusters: _list.index(_cl) print("New cluster found in reload.") assert True except ValueError: assert False # now drop all and repeat check for _cid in _created_clusters: drop_c = DataClusterDropMessage(connection) print("Drop cluster %u" % _cid) res = drop_c.prepare(_cid).send().fetch_response() if res is True: print("Done") else: raise Exception("Cluster " + str(_cid) + " failed") _reload = DbReloadMessage(connection) new_cluster_list = _reload.prepare().send().fetch_response() new_cluster_list.dataClusters.sort(key=lambda cluster: cluster['id']) _list = [] for cluster in new_cluster_list: datarange = DataClusterDataRangeMessage(connection) value = datarange.prepare(cluster['id']).send().fetch_response() print("Cluster Name: %s, ID: %u: %s " \ % ( cluster['name'], cluster['id'], value )) _list.append(cluster['id']) assert value is not [] assert value is not None # check for removed cluster in database for _cl in _created_clusters: try: _list.index(_cl) assert False except ValueError: assert True print("Cluster %u deleted." % _cl)
def test_transaction(self): connection = OrientSocket("localhost", 2424) session_id = ( ConnectMessage( connection ) ).prepare( ("root", "root") )\ .send().fetch_response() db_name = "my_little_test" msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() print("Before %r" % exists) try: ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() assert True except PyOrientCommandException as e: print(str(e)) finally: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_GRAPH, STORAGE_TYPE_PLOCAL)).send().fetch_response() msg = DbOpenMessage(connection) cluster_info = msg.prepare((db_name, "admin", "admin", DB_TYPE_GRAPH, "")).send().fetch_response() try: create_class = CommandMessage(connection) create_class.prepare((QUERY_CMD, "create class my_class extends V"))\ .send().fetch_response() except PyOrientCommandException as e: # class my_class already exists pass # ################## # execute real create rec0 = {'alloggio': 'baita', 'lavoro': 'no', 'vacanza': 'lago'} real_record1 = ( RecordCreateMessage(connection) )\ .prepare( ( 3, rec0 ) )\ .send().fetch_response() ####################### # prepare for an update rec3 = {'alloggio': 'ciao', 'lavoro': 'ciao2', 'vacanza': 'ciao3'} temp_update_real_rec = ( RecordUpdateMessage(connection) )\ .prepare( ( 3, real_record1._rid, rec3, real_record1._version ) ) # prepare transaction rec1 = {'alloggio': 'casa', 'lavoro': 'ufficio', 'vacanza': 'mare'} temp_record1 = ( RecordCreateMessage(connection) )\ .prepare( ( -1, rec1 ) ) rec2 = {'alloggio': 'baita', 'lavoro': 'no', 'vacanza': 'lago'} temp_record2 = ( RecordCreateMessage(connection) )\ .prepare( ( -1, rec2 ) ) delete_real_rec = RecordDeleteMessage(connection) delete_real_rec.prepare((3, real_record1._rid)) ####################### # create another real record rec = {'alloggio': 'bim', 'lavoro': 'bum', 'vacanza': 'bam'} real_record1 = ( RecordCreateMessage(connection) )\ .prepare( ( 3, rec ) )\ .send().fetch_response() tx = TxCommitMessage(connection) tx.begin() tx.attach(temp_record1) tx.attach(temp_record2) tx.attach(temp_update_real_rec) tx.attach(delete_real_rec) res = tx.commit() for k, v in res.items(): print(k + " -> " + v.vacanza) assert len(res) == 2 assert res["#3:2"].vacanza == 'mare' assert res["#3:3"].vacanza == 'lago' sid = ( ConnectMessage( connection ) ).prepare( ("root", "root") )\ .send().fetch_response() # # at the end drop the test database ( DbDropMessage( connection ) ).prepare([db_name, STORAGE_TYPE_MEMORY]) \ .send().fetch_response()
def test_db_drop_without_connect(self): connection = OrientSocket("localhost", 2424) with self.assertRaises(PyOrientException): ( DbDropMessage( connection ) ).prepare(["test"]) \ .send().fetch_response()
def test_not_singleton_socket(self): connection = OrientSocket("localhost", 2424) connection2 = OrientSocket("localhost", 2424) assert id(connection.get_connection()) != id( connection2.get_connection())
def test_not_singleton_socket(self): connection = OrientSocket( "localhost", 2424 ) connection2 = OrientSocket( "localhost", 2424 ) assert id(connection.get_connection()) != id(connection2.get_connection())
def test_record_create_update(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) assert connection.protocol != -1 session_id = conn_msg.prepare( ("root", "root") ) \ .send().fetch_response() assert session_id == connection.session_id assert session_id != -1 # ################## db_name = "my_little_test" msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() print("Before %r" % exists) try: ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() assert True except PyOrientCommandException as e: print(str(e)) finally: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_GRAPH, STORAGE_TYPE_MEMORY)).send().fetch_response() msg = DbOpenMessage(connection) cluster_info = msg.prepare((db_name, "admin", "admin", DB_TYPE_GRAPH, "")).send().fetch_response() assert len(cluster_info) != 0 try: create_class = CommandMessage(connection) cluster = create_class.prepare((QUERY_CMD, "create class my_class " "extends V"))\ .send().fetch_response()[0] except PyOrientCommandException: # class my_class already exists pass # classes are not allowed in record create/update/load rec = { '@my_class': { 'alloggio': 'casa', 'lavoro': 'ufficio', 'vacanza': 'mare' } } rec_position = ( RecordCreateMessage(connection) )\ .prepare( ( cluster, rec ) )\ .send().fetch_response() print("New Rec Position: %s" % rec_position._rid) assert rec_position._rid is not None rec = { '@my_class': { 'alloggio': 'albergo', 'lavoro': 'ufficio', 'vacanza': 'montagna' } } update_success = ( RecordUpdateMessage(connection) )\ .prepare( ( cluster, rec_position._rid, rec ) )\ .send().fetch_response() assert update_success[0] != 0 if connection.protocol <= 21: return unittest.skip("Protocol {!r} does not works well".format( connection.protocol)) # skip test res = ( CommandMessage( connection ) )\ .prepare( [ QUERY_SYNC, "select from " + rec_position._rid ] )\ .send().fetch_response() # res = [ ( RecordLoadMessage(connection) ).prepare( # [ rec_position._rid ] # ).send().fetch_response() ] print("%r" % res[0]._rid) print("%r" % res[0]._class) print("%r" % res[0]._version) print("%r" % res[0].alloggio) print("%r" % res[0].lavoro) print("%r" % res[0].vacanza) assert res[0]._rid == '#11:0' assert res[0]._class == 'my_class' assert res[0]._version >= 0 assert res[0].alloggio == 'albergo' assert res[0].lavoro == 'ufficio' assert res[0].vacanza == 'montagna' sid = ( ConnectMessage( connection ) ).prepare( ("root", "root") ) \ .send().fetch_response() # at the end drop the test database ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response()
def test_record_create_update(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) assert connection.protocol != -1 session_id = conn_msg.prepare( ("admin", "admin") ) \ .send().fetch_response() assert session_id == connection.session_id assert session_id != -1 # ################## db_name = "my_little_test" msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() print("Before %r" % exists) try: ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() assert True except PyOrientCommandException as e: print(str(e)) finally: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_DOCUMENT, STORAGE_TYPE_PLOCAL)).send().fetch_response() msg = DbOpenMessage(connection) cluster_info = msg.prepare((db_name, "admin", "admin", DB_TYPE_GRAPH, "")).send().fetch_response() assert len(cluster_info) != 0 try: create_class = CommandMessage(connection) create_class.prepare((QUERY_CMD, "create class my_class extends V"))\ .send().fetch_response() except PyOrientCommandException: # class my_class already exists pass # classes are not allowed in record create/update/load rec = { '@my_class': { 'alloggio': 'casa', 'lavoro': 'ufficio', 'vacanza': 'mare' } } rec_position = ( RecordCreateMessage(connection) )\ .prepare( ( 1, rec ) )\ .send().fetch_response() print("New Rec Position: %s" % rec_position.rid) assert rec_position.rid is not None rec = { '@my_class': { 'alloggio': 'albergo', 'lavoro': 'ufficio', 'vacanza': 'montagna' } } update_success = ( RecordUpdateMessage(connection) )\ .prepare( ( 1, rec_position.rid, rec ) )\ .send().fetch_response() assert update_success[0] != 0 res = ( CommandMessage( connection ) )\ .prepare( [ QUERY_SYNC, "select from " + rec_position.rid ] )\ .send().fetch_response() print("%r" % res[0].rid) print("%r" % res[0].o_class) print("%r" % res[0].version) print("%r" % res[0].alloggio) print("%r" % res[0].lavoro) print("%r" % res[0].vacanza) assert res[0].rid == '#1:2' assert res[0].o_class is None assert res[0].version >= 0 assert res[0].alloggio == 'albergo' assert res[0].lavoro == 'ufficio' assert res[0].vacanza == 'montagna' # at the end drop the test database ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response()
def test_record_delete(self): connection = OrientSocket("localhost", 2424) conn_msg = ConnectMessage(connection) assert connection.protocol != -1 session_id = conn_msg.prepare( ("admin", "admin") ) \ .send().fetch_response() print("Sid: %s" % session_id) assert session_id == connection.session_id assert session_id != -1 db_name = "my_little_test" msg = DbExistsMessage(connection) exists = msg.prepare([db_name]).send().fetch_response() print("Before %r" % exists) try: ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response() assert True except PyOrientCommandException as e: print(str(e)) finally: (DbCreateMessage(connection)).prepare( (db_name, DB_TYPE_DOCUMENT, STORAGE_TYPE_PLOCAL)).send().fetch_response() msg = DbOpenMessage(connection) cluster_info = msg.prepare( (db_name, "admin", "admin", DB_TYPE_DOCUMENT, "")).send().fetch_response() assert len(cluster_info) != 0 rec = {'alloggio': 'casa', 'lavoro': 'ufficio', 'vacanza': 'mare'} rec_position = ( RecordCreateMessage(connection) )\ .prepare( ( 1, rec ) )\ .send().fetch_response() print("New Rec Position: %s" % rec_position.rid) assert rec_position.rid is not None ######################## Check Success res = ( CommandMessage( connection ) )\ .prepare( [ QUERY_SYNC, "select from " + str(rec_position.rid) ] )\ .send().fetch_response() assert res[0].rid == '#1:2' assert res[0].o_class is None assert res[0].version >= 0 assert res[0].alloggio == 'casa' assert res[0].lavoro == 'ufficio' assert res[0].vacanza == 'mare' ######################## Delete Rid del_msg = (RecordDeleteMessage(connection)) deletion = del_msg.prepare( ( 1, rec_position.rid ) )\ .send().fetch_response() assert deletion is True # now try a failure in deletion for wrong rid del_msg = (RecordDeleteMessage(connection)) deletion = del_msg.prepare( ( 1, 11111 ) )\ .send().fetch_response() assert deletion is False # at the end drop the test database ( DbDropMessage( connection ) ).prepare([db_name]) \ .send().fetch_response()