summaryrefslogtreecommitdiff
path: root/src-py/test_db_controller.py
blob: 6e3a42ffe9aa6b5c01bb959cf80511c76d57cfa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import unittest
import db_controller
import logging
import db_controller as dbc

from rhizi_server import Config

class TestDBController(unittest.TestCase):

    db_ctl = None
    log = None

    n_map = { 'Skill': [{'name': 'kung fu', 'id': 'skill_00' },
                            {'name': 'judo', 'id': 'skill_01' }
                           ],
                  'Person': [{'name': 'Bob', 'id': 'person_00' },
                             {'name': 'Alice', 'id': 'person_01' }]
            }

    @classmethod
    def setUpClass(self):
        cfg = Config.init_from_file('res/etc/rhizi-backend.conf')
        self.log = logging.getLogger('rhizi')
        self.db_ctl = dbc.DB_Controller(cfg)

    def setUp(self):
        self.flush_db()

    def flush_db(self):
        """
        complete DB flush: remove all nodes & links
        """
        self.db_ctl.exec_cypher_query('match ()-[r]-() delete r')
        self.db_ctl.exec_cypher_query('match (n) delete n')

    def test_node_lifecycle(self):
        """
        test node commit & load
        """

        self.db_ctl.exec_op(dbc.DBO_add_node_set(self.n_map))
        n_set = self.db_ctl.exec_op(dbc.DBO_load_node_set_by_id_attribute(['skill_00', 'person_01']))
        self.assertEqual(len(n_set), 2, 'incorrect result size')

    def tearDown(self): pass

if __name__ == "__main__":
    unittest.main()