def test_hi_level_interface(self):

        factory = pyorient.OrientDB('localhost', 2424)

        factory.get_message( pyorient.CONNECT ).prepare( ("root", "root") )\
            .send().fetch_response()

        db_name = 'demo_db'

        exists = factory.get_message( pyorient.DB_EXIST )\
            .prepare( [db_name, pyorient.STORAGE_TYPE_MEMORY] )\
            .send().fetch_response()

        print("Before %r" % exists)
        try:
            ( factory.get_message( pyorient.DB_DROP ) ).prepare([db_name]) \
                .send().fetch_response()
            assert True
        except pyorient.PyOrientCommandException as e:
            print(str(e))
        finally:
            ( factory.get_message( pyorient.DB_CREATE ) ).prepare(
                (db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY)
            ).send().fetch_response()

        msg = factory.get_message( pyorient.DB_OPEN )
        clusters = msg.prepare(
            (db_name, "admin", "admin", pyorient.DB_TYPE_GRAPH, "")
        ).send().fetch_response()

        #######################################

        try:
            create_class = factory.get_message( pyorient.COMMAND )
            """:type create_class: pyorient.Messages.Database.CommandMessage"""
            create_class.prepare( ( pyorient.QUERY_CMD, "create class demo_class" ) )\
                .send().fetch_response()
            clusters = factory.get_message(pyorient.DB_RELOAD).prepare()\
                .send().fetch_response()
        except pyorient.PyOrientCommandException:
            pass

        from random import randint
        rec = { 'Nome': 'Dome', 'Cognome': 'Nico', 'test': str(randint(0, 999999999)) }

        insert_query = 'insert into demo_class ( {0} ) values( {1} )'.format(
            ",".join( rec.keys() ), "'" + "','".join( rec.values() ) + "'"
        )

        insert = factory.get_message( pyorient.COMMAND )\
            .prepare( ( pyorient.QUERY_CMD, insert_query ) )
        sql_insert_result = insert.send().fetch_response()

        cluster = 1
        for x in clusters:
            if x.name == 'demo_class':
                cluster = x.id
                break

        load = ( factory.get_message(pyorient.RECORD_CREATE) )\
            .prepare( [cluster, rec] )\
            .send().fetch_response()

        factory.get_message( pyorient.CONNECT ).prepare( ("root", "root") )\
            .send().fetch_response()

        drop_db_result = ( factory.get_message(pyorient.DB_DROP) )\
            .prepare(['demo_db', pyorient.STORAGE_TYPE_MEMORY])\
            .send().fetch_response()


        assert len( clusters ) != 0
        assert isinstance( sql_insert_result, list )
        assert len( sql_insert_result ) == 1
        assert isinstance( load, pyorient.OrientRecord )
        assert load._rid != -1
        assert isinstance( drop_db_result, list )
        assert len( drop_db_result ) == 0
dataset/ETHPy150Open mogui/pyorient/tests/test_Factory_and_usage.py/CommandTestCase.test_hi_level_interface/original