<s> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> import os <EOL> import sys <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT:1>" <EOL> os . environ [ '<STR_LIT>' ] = "<STR_LIT:0>" <EOL> import pyorient <EOL> class CommandTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_hi_level_interface ( self ) : <EOL> factory = pyorient . OrientDB ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> factory . get_message ( pyorient . CONNECT ) . prepare ( ( "<STR_LIT:root>" , "<STR_LIT:root>" ) ) . send ( ) . fetch_response ( ) <EOL> db_name = '<STR_LIT>' <EOL> exists = factory . get_message ( pyorient . DB_EXIST ) . prepare ( [ db_name , pyorient . STORAGE_TYPE_MEMORY ] ) . send ( ) . fetch_response ( ) <EOL> print ( "<STR_LIT>" % exists ) <EOL> try : <EOL> ( factory . get_message ( pyorient . DB_DROP ) ) . prepare ( [ db_name ] ) . send ( ) . fetch_response ( ) <EOL> assert True <EOL> except pyorient . PyOrientCommandException as e : <EOL> print ( str ( e ) ) <EOL> finally : <EOL> ( factory . get_message ( pyorient . DB_CREATE ) ) . prepare ( <EOL> ( db_name , pyorient . DB_TYPE_GRAPH , pyorient . STORAGE_TYPE_MEMORY ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> msg = factory . get_message ( pyorient . DB_OPEN ) <EOL> clusters = msg . prepare ( <EOL> ( db_name , "<STR_LIT>" , "<STR_LIT>" , pyorient . DB_TYPE_GRAPH , "<STR_LIT>" ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> try : <EOL> create_class = factory . get_message ( pyorient . COMMAND ) <EOL> """<STR_LIT>""" <EOL> create_class . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) . send ( ) . fetch_response ( ) <EOL> clusters = factory . get_message ( pyorient . DB_RELOAD ) . prepare ( ) . send ( ) . fetch_response ( ) <EOL> except pyorient . PyOrientCommandException : <EOL> pass <EOL> from random import randint <EOL> rec = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:test>' : str ( randint ( <NUM_LIT:0> , <NUM_LIT> ) ) } <EOL> insert_query = '<STR_LIT>' . format ( <EOL> "<STR_LIT:U+002C>" . join ( rec . keys ( ) ) , "<STR_LIT:'>" + "<STR_LIT>" . join ( rec . values ( ) ) + "<STR_LIT:'>" <EOL> ) <EOL> insert = factory . get_message ( pyorient . COMMAND ) . prepare ( ( pyorient . QUERY_CMD , insert_query ) ) <EOL> sql_insert_result = insert . send ( ) . fetch_response ( ) <EOL> cluster = <NUM_LIT:1> <EOL> for x in clusters : <EOL> if x . name == '<STR_LIT>' : <EOL> cluster = x . id <EOL> break <EOL> load = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( [ cluster , rec ] ) . send ( ) . fetch_response ( ) <EOL> factory . get_message ( pyorient . CONNECT ) . prepare ( ( "<STR_LIT:root>" , "<STR_LIT:root>" ) ) . send ( ) . fetch_response ( ) <EOL> drop_db_result = ( factory . get_message ( pyorient . DB_DROP ) ) . prepare ( [ '<STR_LIT>' , pyorient . STORAGE_TYPE_MEMORY ] ) . send ( ) . fetch_response ( ) <EOL> assert len ( clusters ) != <NUM_LIT:0> <EOL> assert isinstance ( sql_insert_result , list ) <EOL> assert len ( sql_insert_result ) == <NUM_LIT:1> <EOL> assert isinstance ( load , pyorient . OrientRecord ) <EOL> assert load . _rid != - <NUM_LIT:1> <EOL> assert isinstance ( drop_db_result , list ) <EOL> assert len ( drop_db_result ) == <NUM_LIT:0> <EOL> def test_hi_level_transaction ( self ) : <EOL> factory = pyorient . OrientDB ( '<STR_LIT:localhost>' , <NUM_LIT> ) <EOL> factory . get_message ( pyorient . CONNECT ) . prepare ( ( "<STR_LIT:root>" , "<STR_LIT:root>" ) ) . send ( ) . fetch_response ( ) <EOL> db_name = '<STR_LIT>' <EOL> exists = factory . get_message ( pyorient . DB_EXIST ) . prepare ( [ db_name , pyorient . STORAGE_TYPE_MEMORY ] ) . send ( ) . fetch_response ( ) <EOL> print ( "<STR_LIT>" % exists ) <EOL> try : <EOL> ( factory . get_message ( pyorient . DB_DROP ) ) . prepare ( [ db_name ] ) . send ( ) . fetch_response ( ) <EOL> assert True <EOL> except pyorient . PyOrientCommandException as e : <EOL> print ( str ( e ) ) <EOL> finally : <EOL> ( factory . get_message ( pyorient . DB_CREATE ) ) . prepare ( <EOL> ( db_name , pyorient . DB_TYPE_GRAPH , pyorient . STORAGE_TYPE_MEMORY ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> msg = factory . get_message ( pyorient . DB_OPEN ) <EOL> cluster_info = msg . prepare ( <EOL> ( db_name , "<STR_LIT>" , "<STR_LIT>" , pyorient . DB_TYPE_GRAPH , "<STR_LIT>" ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> rec = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> rec_position = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( ( <NUM_LIT:3> , rec ) ) . send ( ) . fetch_response ( ) <EOL> rec3 = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> update_success = ( factory . get_message ( pyorient . RECORD_UPDATE ) ) . prepare ( ( <NUM_LIT:3> , rec_position . _rid , rec3 , rec_position . _version ) ) <EOL> rec1 = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> rec_position1 = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( ( - <NUM_LIT:1> , rec1 ) ) <EOL> rec2 = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> rec_position2 = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( ( - <NUM_LIT:1> , rec2 ) ) <EOL> rec = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> rec_position = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( ( <NUM_LIT:3> , rec ) ) . send ( ) . fetch_response ( ) <EOL> delete_msg = ( factory . get_message ( pyorient . RECORD_DELETE ) ) <EOL> delete_msg . prepare ( ( <NUM_LIT:3> , rec_position . _rid ) ) <EOL> tx = ( factory . get_message ( pyorient . TX_COMMIT ) ) <EOL> tx . begin ( ) <EOL> tx . attach ( rec_position1 ) <EOL> tx . attach ( rec_position1 ) <EOL> tx . attach ( rec_position2 ) <EOL> tx . attach ( update_success ) <EOL> tx . attach ( delete_msg ) <EOL> res = tx . commit ( ) <EOL> for k , v in res . items ( ) : <EOL> print ( k + "<STR_LIT>" + v . vacanza ) <EOL> assert len ( res ) == <NUM_LIT:4> <EOL> assert res [ "<STR_LIT>" ] . vacanza == '<STR_LIT>' <EOL> assert res [ "<STR_LIT>" ] . vacanza == '<STR_LIT>' <EOL> assert res [ "<STR_LIT>" ] . vacanza == '<STR_LIT>' <EOL> assert res [ "<STR_LIT>" ] . vacanza == '<STR_LIT>' <EOL> sid = ( factory . get_message ( pyorient . CONNECT ) ) . prepare ( ( "<STR_LIT:root>" , "<STR_LIT:root>" ) ) . send ( ) . fetch_response ( ) <EOL> ( factory . get_message ( pyorient . DB_DROP ) ) . prepare ( <EOL> [ db_name , pyorient . STORAGE_TYPE_MEMORY ] ) . send ( ) . fetch_response ( ) <EOL> def test_command ( self ) : <EOL> connection = pyorient . OrientSocket ( "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> factory = pyorient . OrientDB ( connection ) <EOL> session_id = ( factory . get_message ( pyorient . CONNECT ) ) . prepare ( ( "<STR_LIT:root>" , "<STR_LIT:root>" ) ) . send ( ) . fetch_response ( ) <EOL> db_name = "<STR_LIT>" <EOL> try : <EOL> ( factory . get_message ( pyorient . DB_DROP ) ) . prepare ( [ db_name , pyorient . STORAGE_TYPE_MEMORY ] ) . send ( ) . fetch_response ( ) <EOL> except pyorient . PyOrientCommandException as e : <EOL> print ( str ( e ) ) <EOL> finally : <EOL> ( factory . get_message ( pyorient . DB_CREATE ) ) . prepare ( <EOL> ( db_name , pyorient . DB_TYPE_GRAPH , pyorient . STORAGE_TYPE_MEMORY ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> msg = factory . get_message ( pyorient . DB_OPEN ) <EOL> cluster_info = msg . prepare ( <EOL> ( db_name , "<STR_LIT>" , "<STR_LIT>" , pyorient . DB_TYPE_DOCUMENT , "<STR_LIT>" , pyorient . OrientSerialization . CSV ) <EOL> ) . send ( ) . fetch_response ( ) <EOL> create_class = factory . get_message ( pyorient . COMMAND ) <EOL> ins_msg1 = factory . get_message ( pyorient . COMMAND ) <EOL> ins_msg2 = factory . get_message ( pyorient . COMMAND ) <EOL> ins_msg3 = factory . get_message ( pyorient . COMMAND ) <EOL> ins_msg4 = factory . get_message ( pyorient . COMMAND ) <EOL> upd_msg5 = factory . get_message ( pyorient . RECORD_UPDATE ) <EOL> req_msg = factory . get_message ( pyorient . COMMAND ) <EOL> create_class . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) <EOL> ins_msg1 . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) <EOL> ins_msg2 . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) <EOL> ins_msg3 . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) <EOL> ins_msg4 . prepare ( ( pyorient . QUERY_CMD , "<STR_LIT>" ) ) <EOL> cluster = create_class . send ( ) . fetch_response ( ) <EOL> rec1 = ins_msg1 . send ( ) . fetch_response ( ) <EOL> rec2 = ins_msg2 . send ( ) . fetch_response ( ) <EOL> rec3 = ins_msg3 . send ( ) . fetch_response ( ) <EOL> rec4 = ins_msg4 . send ( ) . fetch_response ( ) <EOL> rec1 = rec1 [ <NUM_LIT:0> ] <EOL> upd_res = upd_msg5 . prepare ( ( rec1 . _rid , rec1 . _rid , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) ) . send ( ) . fetch_response ( ) <EOL> res = req_msg . prepare ( [ pyorient . QUERY_SYNC , "<STR_LIT>" ] ) . send ( ) . fetch_response ( ) <EOL> assert isinstance ( cluster , list ) <EOL> assert rec1 . _rid == res [ <NUM_LIT:0> ] . _rid <EOL> assert rec1 . _version != res [ <NUM_LIT:0> ] . _version <EOL> assert res [ <NUM_LIT:0> ] . _version == upd_res [ <NUM_LIT:0> ] . _version <EOL> assert len ( res ) == <NUM_LIT:4> <EOL> assert res [ <NUM_LIT:0> ] . _rid == '<STR_LIT>' <EOL> assert res [ <NUM_LIT:0> ] . Band == '<STR_LIT>' <EOL> assert res [ <NUM_LIT:0> ] . Song == '<STR_LIT>' <EOL> assert res [ <NUM_LIT:3> ] . Song == '<STR_LIT>' <EOL> rec = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } } <EOL> rec_position = ( factory . get_message ( pyorient . RECORD_CREATE ) ) . prepare ( ( cluster [ <NUM_LIT:0> ] , rec ) ) . send ( ) . fetch_response ( ) <EOL> print ( "<STR_LIT>" % rec_position . _rid ) <EOL> assert rec_position . _rid is not None <EOL> rec = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } } <EOL> update_success = ( factory . get_message ( pyorient . RECORD_UPDATE ) ) . prepare ( ( rec_position . _rid , rec_position . _rid , rec ) ) . send ( ) . fetch_response ( ) <EOL> req_msg = factory . get_message ( pyorient . RECORD_LOAD ) <EOL> res = req_msg . prepare ( [ rec_position . _rid , "<STR_LIT>" ] ) . send ( ) . fetch_response ( ) <EOL> assert res . _rid == "<STR_LIT>" <EOL> assert res . _class == "<STR_LIT>" <EOL> assert res . alloggio == '<STR_LIT>' <EOL> assert not hasattr ( res , '<STR_LIT>' ) <EOL> assert not hasattr ( res , '<STR_LIT>' ) </s>
