# Path: rhizi/db_op.py
# class DBO_raw_query_set(DB_op):
#     """
#     Freeform set of DB query statements
# 
#     [!] use of this class is discouraged and should be done
#         only when no other DB_op is able to handle the task
#         at hand
#     """
#     def __init__(self, q_arr=None, q_params={}):
#         super(DBO_raw_query_set, self).__init__()
# 
#         if q_arr is not None:
#             self.add_statement(q_arr, q_params)
# 
#     def add_statement(self, q_arr, query_params={}):
#         """
#         super.add_statement() override: use raw queries
#         """
#         db_q = DB_Raw_Query(q_arr, query_params)
#         self.query_set.append(db_q)
#         return len(self.query_set)
# 
#     def add_db_query(self, db_q):
#         assert False, 'DBO_raw_query_set only supports raw queries - use add_statement()'
# 
# Path: rhizi/tests/util.py
# class RhiziTestBase(TestCase):
# 
#     @classmethod
#     def setUpClass(clz):
# 
#         db_ctl, kernel = get_connection()
#         clz.cfg = cfg
#         clz.db_ctl = db_ctl
#         clz.user_db = user_db
#         rz_api.db_ctl = clz.db_ctl
#         clz.kernel = kernel
#         clz.webapp = webapp
# 
#     def _json_post(self, c, path, payload):
#         req = c.post(path, content_type='application/json', data=json.dumps(payload))
#         resp = json.loads(req.data.decode('utf-8'))
#         return req, resp


import json
import unittest
from rhizi.db_op import DBO_raw_query_set
from rhizi.tests.test_util__pydev import debug__pydev_pd_arg
from rhizi.tests.util import RhiziTestBase

            req, req_data = self._json_post(c, '/api/rzdoc/search', {'search_query': self.rzdoc_name})
            self.assertEqual(req.status_code, 200)
            self.assertIn(self.rzdoc_name, req_data["data"])
            self.assertEqual(req_data["error"], None)

    def test_search_error(self):
        """Wrong query in API search should raise error"""
        with self.webapp.test_client() as c:
            req, req_data = self._json_post(c, '/api/rzdoc/search', {'search_query': "random non-existing stuff"})

            self.assertEqual(req.status_code, 200)
            self.assertEqual(req_data["data"], [])
            self.assertEqual(req_data["error"], None )

    # Fetch nodes sets
    def test_load_node_non_existing(self):
        """ Loading a non existing node test """
        id_set = ['non_existing_id']
        with self.webapp.test_client() as c:
            req, req_data = self._json_post(c, '/api/rzdoc/fetch/node-set-by-id', { 'id_set': id_set, 'rzdoc_name': self.rzdoc_name})
            rz_data = req_data['data']
            rz_err = req_data['error']
            self.assertEqual(None, rz_err)
            self.assertEqual(0, len(rz_data))

    def test_load_node_set_by_id_existing(self):
        """ Loading an existing node test """
        id_set = ['skill_00']
        q = ['create (s:Skill {id: \'skill_00\'} )']

# Path: rhizi/db_op.py
# class DBO_raw_query_set(DB_op):
#     """
#     Freeform set of DB query statements
# 
#     [!] use of this class is discouraged and should be done
#         only when no other DB_op is able to handle the task
#         at hand
#     """
#     def __init__(self, q_arr=None, q_params={}):
#         super(DBO_raw_query_set, self).__init__()
# 
#         if q_arr is not None:
#             self.add_statement(q_arr, q_params)
# 
#     def add_statement(self, q_arr, query_params={}):
#         """
#         super.add_statement() override: use raw queries
#         """
#         db_q = DB_Raw_Query(q_arr, query_params)
#         self.query_set.append(db_q)
#         return len(self.query_set)
# 
#     def add_db_query(self, db_q):
#         assert False, 'DBO_raw_query_set only supports raw queries - use add_statement()'
# 
# Path: rhizi/tests/util.py
# class RhiziTestBase(TestCase):
# 
#     @classmethod
#     def setUpClass(clz):
# 
#         db_ctl, kernel = get_connection()
#         clz.cfg = cfg
#         clz.db_ctl = db_ctl
#         clz.user_db = user_db
#         rz_api.db_ctl = clz.db_ctl
#         clz.kernel = kernel
#         clz.webapp = webapp
# 
#     def _json_post(self, c, path, payload):
#         req = c.post(path, content_type='application/json', data=json.dumps(payload))
#         resp = json.loads(req.data.decode('utf-8'))
#         return req, resp


# Path: rhizi/tests/test_rz_API_rzdoc.py
import json
import unittest
from rhizi.db_op import DBO_raw_query_set
from rhizi.tests.test_util__pydev import debug__pydev_pd_arg
from rhizi.tests.util import RhiziTestBase


            req, req_data = self._json_post(c, '/api/rzdoc/search', {'search_query': self.rzdoc_name})
            self.assertEqual(req.status_code, 200)
            self.assertIn(self.rzdoc_name, req_data["data"])
            self.assertEqual(req_data["error"], None)

    def test_search_error(self):
        """Wrong query in API search should raise error"""
        with self.webapp.test_client() as c:
            req, req_data = self._json_post(c, '/api/rzdoc/search', {'search_query': "random non-existing stuff"})

            self.assertEqual(req.status_code, 200)
            self.assertEqual(req_data["data"], [])
            self.assertEqual(req_data["error"], None )

    # Fetch nodes sets
    def test_load_node_non_existing(self):
        """ Loading a non existing node test """
        id_set = ['non_existing_id']
        with self.webapp.test_client() as c:
            req, req_data = self._json_post(c, '/api/rzdoc/fetch/node-set-by-id', { 'id_set': id_set, 'rzdoc_name': self.rzdoc_name})
            rz_data = req_data['data']
            rz_err = req_data['error']
            self.assertEqual(None, rz_err)
            self.assertEqual(0, len(rz_data))

    def test_load_node_set_by_id_existing(self):
        """ Loading an existing node test """
        id_set = ['skill_00']
        q = ['create (s:Skill {id: \'skill_00\'} )']

        op = DBO_raw_query_set(q)