コード例 #1
0
ファイル: test_rz_mesh.py プロジェクト: yuvadm/rhizi
    def test_REST_post_triggers_ws_multicast__topo_diff(self):

        class NS_test(BaseNamespace):

            def on_diff_commit__topo(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt()  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)
        topo_diff = Topo_Diff(node_set_add=[n])

        def c_0():

            with RZ_websocket(namespace=NS_test) as (sock, _):
                c1_t.switch()  # allow peer to POST
                sock.wait(8)  # allow self to receive

        def c_1():
            data = json.dumps({'topo_diff': topo_diff.to_json_dict()})
            req = urllib2.Request(url='http://rhizi.local:8080/graph/diff-commit-topo',
                                  data=data,
                                  headers={'Content-Type': 'application/json'})

            f = urllib2.urlopen(req)
            f.close()
            c0_t.switch()

        c0_t = greenlet(c_0)
        c0_t.data = None
        c1_t = greenlet(c_1)
        c0_t.switch()

        self.assertTrue(None != c0_t.data)
        self.assertEqual(2, len(c1_t.data))
コード例 #2
0
    def test_REST_post_triggers_ws_multicast__topo_diff(self):
        class NS_test(BaseNamespace):
            def on_diff_commit__topo(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt(
                )  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)
        topo_diff = Topo_Diff(node_set_add=[n])

        def c_0():

            with RZ_websocket(namespace=NS_test) as (sock, _):
                c1_t.switch()  # allow peer to POST
                sock.wait(8)  # allow self to receive

        def c_1():
            data = json.dumps({'topo_diff': topo_diff.to_json_dict()})
            req = urllib2.Request(
                url='http://rhizi.local:8080/graph/diff-commit-topo',
                data=data,
                headers={'Content-Type': 'application/json'})

            f = urllib2.urlopen(req)
            f.close()
            c0_t.switch()

        c0_t = greenlet(c_0)
        c0_t.data = None
        c1_t = greenlet(c_1)
        c0_t.switch()

        self.assertTrue(None != c0_t.data)
        self.assertEqual(2, len(c1_t.data))
コード例 #3
0
ファイル: test_neo4j_cypher.py プロジェクト: yuvadm/rhizi
    def test_T__add_node_filter__meta_label(self):
        test_label = neo4j_test_util.rand_label()

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)
        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for _idx, db_q, _db_q_result in op:
                dbq_set.append(db_q)

        self.test_T__common(dbq_set, DB_Query.t__add_node_filter__meta_label)
コード例 #4
0
    def test_T__add_node_filter__meta_label(self):
        test_label = neo4j_test_util.rand_label()

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)
        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for _idx, db_q, _db_q_result in op.iter__r_set():
                dbq_set.append(db_q)

        self.test_T__common(dbq_set, DB_Query.t__add_node_filter__meta_label)
コード例 #5
0
ファイル: test_db_controller.py プロジェクト: shlomif/rhizi
    def test_add_node_set(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_map = meta_attr_list_to_meta_attr_map([n_0, n_1])
        op = DBO_add_node_set(n_map)

        self.assertEqual(len(op.statement_set), 1)  # assert a single statement is issued

        ret_id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_id_set), 2)
        self.assertTrue(n_0_id in ret_id_set)
        self.assertTrue(n_1_id in ret_id_set)
コード例 #6
0
    def test_add_node_set(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_map = meta_attr_list_to_meta_attr_map([n_0, n_1])
        op = DBO_add_node_set(n_map)

        self.assertEqual(len(op.statement_set),
                         1)  # assert a single statement is issued

        ret_id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_id_set), 2)
        self.assertTrue(n_0_id in ret_id_set)
        self.assertTrue(n_1_id in ret_id_set)
コード例 #7
0
ファイル: test_rz_mesh.py プロジェクト: yuvadm/rhizi
    def test_ws_event__attr_diff(self):

        class NS_test(BaseNamespace):

            def on_diff_commit__attr(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt()  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_id, 'attr_2')

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(attr_diff)
                ns_sock.emit('diff_commit__attr', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Attr_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Attr_Diff.from_json_dict(c1_t.data[1])

        self.assertEqual(Attr_Diff, type(diff_in))
        self.assertEqual(Attr_Diff, type(commit_ret))
コード例 #8
0
ファイル: test_neo4j_cypher.py プロジェクト: yuvadm/rhizi
    def test_T__add_node_filter__rzdoc_id_label(self):
        test_label = neo4j_test_util.rand_label()
        test_rzdoc = generate_random_RZDoc(test_label)

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)

        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for dbq in op:
                dbq_set.append(dbq)

        q_arr = ['match (n)-[l_old {id: {id}}]->(m)',
                 'where type(l_old)<>\'is not\'',
                 'delete l_old, params: {\'id\': u\'9fbhxwcn\'}']
        dbq = DB_Query(q_arr)
        dbq_set = [dbq]

        # dbq_set = dbq_set[:1]
        self.test_T__common(dbq_set, QT_RZDOC_NS_Filter, test_rzdoc)
コード例 #9
0
    def test_T__add_node_filter__rzdoc_id_label(self):
        test_label = neo4j_test_util.rand_label()
        test_rzdoc = generate_random_RZDoc(test_label)

        dbq_set = []
        op_set = self.gen_full_db_op_set(test_label)

        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # sub-queries tested instead
            for dbq in op:
                dbq_set.append(dbq)

        q_arr = ['match (n)-[l_old {id: {id}}]->(m)',
                 'where type(l_old)<>\'is not\'',
                 'delete l_old, params: {\'id\': u\'9fbhxwcn\'}']
        dbq = DB_Query(q_arr)
        dbq_set = [dbq]

        # dbq_set = dbq_set[:1]
        self.test_T__common(dbq_set, QT_RZDOC_NS_Filter, test_rzdoc)
コード例 #10
0
    def test_ws_event__attr_diff(self):
        class NS_test(BaseNamespace):
            def on_diff_commit__attr(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt(
                )  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_id, 'attr_2')

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(attr_diff)
                ns_sock.emit('diff_commit__attr', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Attr_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Attr_Diff.from_json_dict(c1_t.data[1])

        self.assertEqual(Attr_Diff, type(diff_in))
        self.assertEqual(Attr_Diff, type(commit_ret))
コード例 #11
0
ファイル: test_rzdoc.py プロジェクト: yuvadm/rhizi
    def test_rzdoc_lifecycle(self):
        test_label = neo4j_test_util.rand_label()

        rzdoc_name = test_label
        lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzdoc_name)
        self.assertIsNone(lookup_ret__by_name)

        # create
        rzdoc, m_rzdoc = self.kernel.rzdoc__create(rzdoc_name)

        # lookup
        for rzd in [rzdoc, m_rzdoc]:
            lookup_ret__by_id = self.kernel.rzdoc__lookup_by_id(rzd.id)
            lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzd.name)
            self.assertTrue(None != lookup_ret__by_id)
            self.assertTrue(None != lookup_ret__by_name)

        # delete
        self.kernel.rzdoc__delete(rzdoc)
        lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzdoc_name)
        self.assertIsNone(lookup_ret__by_name)
コード例 #12
0
ファイル: test_rzdoc.py プロジェクト: yuvadm/rhizi
    def test_rzdoc_lifecycle(self):
        test_label = neo4j_test_util.rand_label()

        rzdoc_name = test_label
        lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzdoc_name)
        self.assertIsNone(lookup_ret__by_name)

        # create
        rzdoc, m_rzdoc = self.kernel.rzdoc__create(rzdoc_name)

        # lookup
        for rzd in [rzdoc, m_rzdoc]:
            lookup_ret__by_id = self.kernel.rzdoc__lookup_by_id(rzd.id)
            lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzd.name)
            self.assertTrue(None != lookup_ret__by_id)
            self.assertTrue(None != lookup_ret__by_name)

        # delete
        self.kernel.rzdoc__delete(rzdoc)
        lookup_ret__by_name = self.kernel.rzdoc__lookup_by_name(rzdoc_name)
        self.assertIsNone(lookup_ret__by_name)
コード例 #13
0
ファイル: test_db_controller.py プロジェクト: shlomif/rhizi
    def test_add_link_set(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_2, n_2_id = generate_random_node_dict(test_label)

        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)
        l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id)

        n_map = meta_attr_list_to_meta_attr_map([n_0, n_1, n_2])
        op = DBO_add_node_set(n_map)
        self.db_ctl.exec_op(op)

        l_map = { test_label : [l_0, l_1]}
        op = DBO_add_link_set(l_map)
        self.assertEqual(len(op.statement_set), 2)  # no support yet for parameterized statements for link creation

        ret_id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_id_set), 2)
        self.assertTrue(l_0_id in ret_id_set)
        self.assertTrue(l_1_id in ret_id_set)
コード例 #14
0
    def test_ws_event__topo_diff(self):
        class NS_test(BaseNamespace):
            def on_diff_commit__topo(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt(
                )  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = test_util.generate_random_node_dict(test_label)
        n_1, n_1_id = test_util.generate_random_node_dict(test_label)
        l, l_id = test_util.generate_random_link_dict(test_label, n_0_id,
                                                      n_1_id)
        topo_diff = Topo_Diff(node_set_add=[n_0, n_1], link_set_add=[l])

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(topo_diff, cls=Topo_Diff.JSON_Encoder)
                ns_sock.emit('diff_commit__topo', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Topo_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Topo_Diff.Commit_Result_Type.from_json_dict(c1_t.data[1])

        self.assertEqual(Topo_Diff, type(diff_in))
        self.assertEqual(Topo_Diff.Commit_Result_Type, type(commit_ret))
コード例 #15
0
ファイル: test_rz_mesh.py プロジェクト: yuvadm/rhizi
    def test_ws_event__topo_diff(self):

        class NS_test(BaseNamespace):

            def on_diff_commit__topo(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt()  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = test_util.generate_random_node_dict(test_label)
        n_1, n_1_id = test_util.generate_random_node_dict(test_label)
        l, l_id = test_util.generate_random_link_dict(test_label, n_0_id, n_1_id)
        topo_diff = Topo_Diff(node_set_add=[n_0, n_1], link_set_add=[l])

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(topo_diff, cls=Topo_Diff.JSON_Encoder)
                ns_sock.emit('diff_commit__topo', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Topo_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Topo_Diff.Commit_Result_Type.from_json_dict(c1_t.data[1])

        self.assertEqual(Topo_Diff, type(diff_in))
        self.assertEqual(Topo_Diff.Commit_Result_Type, type(commit_ret))
コード例 #16
0
    def test_diff_commit__attr(self):
        # create test node
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_0['attr_0'] = 0
        topo_diff = Topo_Diff(node_set_add=[n_0])
        op = DBO_diff_commit__topo(topo_diff)
        self.db_ctl.exec_op(op)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_0_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)

        self.assertEqual(len(ret_diff.type__node), 1)
        self.assertTrue(None != ret_diff.type__node[n_0_id])

        # attr-set only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_2', 0)

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(
            None != ret_diff.type__node[n_0_id]['__attr_write'].get('attr_2'))

        # attr-remove only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(
            'attr_2' in ret_diff.type__node[n_0_id]['__attr_remove'])
コード例 #17
0
    def test_add_link_set(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_2, n_2_id = generate_random_node_dict(test_label)

        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)
        l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id)

        n_map = meta_attr_list_to_meta_attr_map([n_0, n_1, n_2])
        op = DBO_add_node_set(n_map)
        self.db_ctl.exec_op(op)

        l_map = {test_label: [l_0, l_1]}
        op = DBO_add_link_set(l_map)
        self.assertEqual(
            len(op.statement_set),
            2)  # no support yet for parameterized statements for link creation

        ret_id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_id_set), 2)
        self.assertTrue(l_0_id in ret_id_set)
        self.assertTrue(l_1_id in ret_id_set)
コード例 #18
0
ファイル: test_db_controller.py プロジェクト: shlomif/rhizi
    def test_diff_commit__attr(self):
        # create test node
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_0['attr_0'] = 0
        topo_diff = Topo_Diff(node_set_add=[n_0])
        op = DBO_diff_commit__topo(topo_diff)
        self.db_ctl.exec_op(op)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_0_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)

        self.assertEqual(len(ret_diff.type__node), 1)
        self.assertTrue(None != ret_diff.type__node[n_0_id])

        # attr-set only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_2', 0)

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(None != ret_diff.type__node[n_0_id]['__attr_write'].get('attr_2'))

        # attr-remove only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue('attr_2' in ret_diff.type__node[n_0_id]['__attr_remove'])
コード例 #19
0
ファイル: test_domain__CRI.py プロジェクト: shlomif/rhizi
    def test_random_data_generation__domain__CRI(self, export_as_csv=True):
        """
        test:
           - random CRI domain data generation
           - DB dump in cvs format: person x skill x skill-level
        """

        skill_set = ['Cryptocurrency',
                     'Database architecture',
                     'Web-development',
                     'Mobile-development',
                     'Machine learning',
                     'Guitar Playing',
                     'Image processing',
                     'Algebra',
                     'Calculus',
                     'Molecular-Biology',
                     'Graphic design',
                     'Geo-location services',
                     'Drone-building',
                     'Artificial-intelligence',
                     'Distributed information systems',
                     'Wordpress',
                     'Woodworking',
                     'Quality-control',
                     'Video-editing',
                     'Soldering',
                     'Network engineering',
                     'GIT',
                     'Electronic music',
                     'Network administration']

        name_set = ['John',
                    'William',
                    'James',
                    'Charles',
                    'George',
                    'Frank',
                    'Joseph',
                    'Thomas',
                    'Henry',
                    'Robert',
                    'Edward',
                    'Harry',
                    'Walter',
                    'Arthur',
                    'Fred',
                    'Albert',
                    'Samuel',
                    'David',
                    'Louis',
                    'Joe',
                    'Charlie',
                    'Clarence',
                    'Richard',
                    'Andrew',
                    'Daniel',
                    'Ernest',
                    'Mary',
                    'Anna',
                    'Emma',
                    'Elizabeth',
                    'Minnie',
                    'Margaret',
                    'Ida',
                    'Alice',
                    'Bertha',
                    'Sarah',
                    'Annie',
                    'Clara',
                    'Ella',
                    'Florence',
                    'Cora',
                    'Martha',
                    'Laura',
                    'Nellie',
                    'Grace',
                    'Carrie',
                    'Maude',
                    'Mabel',
                    'Bessie',
                    'Jennie',
                    'Gertrude',
                    'Julia']

        test_label = rand_label()
        rzdoc = generate_random_RZDoc(test_label)

        op = DBO_rzdoc__create(rzdoc)
        self.db_ctl.exec_op(op)

        op = DBO_RDG__skill_graph(rzdoc,
                                  lim_n=10,
                                  skill_set=skill_set,
                                  name_set=name_set)
        self.db_ctl.exec_op(op)

        if False == export_as_csv:
            return

        q_arr = ['match (n: Person)',
                 'with n',
                 'match (n)-[r:Novice|Intermediate|Expert]->(m:Skill)',  # [!] expect link type to be proficiency level
                 'return n.name, collect({skill_name: m.name, skill_level: r.proficiency})'
                 ]
        op = DBO_raw_query_set(q_arr)

        #
        # write csv file
        #
        cur_f_name = inspect.stack()[0][3]
        def q_process_result_set():
            with tempfile.NamedTemporaryFile(prefix='rz_%s' % (cur_f_name), dir='/tmp', suffix='.csv', delete=False) as f_out:
                for _, _, r_set in op.iter__r_set():
                    for row in r_set:
                        person_name, skill_dict_set = row  # person to {sname: skill, s:pro: skill_level{ dict set
                        cvs_line_arr = [person_name]
                        for skill_dict in skill_dict_set:
                            skill_name = skill_dict['skill_name']
                            skill_level = skill_dict['skill_level']
                            cvs_line_arr += [skill_name, skill_level]
                        f_out.write(','.join(cvs_line_arr) + '\n')
                f_out.write('\n')

        op.process_result_set = q_process_result_set
        self.db_ctl.exec_op(op)
コード例 #20
0
    def test_cypher_exp_parsing(self):
        def validate_parse_tree(pt, q_str):
            self.log.debug('\n'.join([
                ' q: %s' % (q_str),
                'q\': %s' % (pt.str__cypher_query()),
                'struct: \n%s' % (pt.str__struct_tree()),
            ]))

            if pt.str__cypher_query(
            ) != q_str:  # test for precise query string match
                self.fail()

        valid_exp_set = []
        #
        # parse expression set
        #
        parser = Cypher_Parser()
        exp_set = [
            'create (n:A)-[r:B]->(m:C:D), ({a: 0, b: \'b\'})',
            'match (n) with n order by n.id skip 0 limit 2 optional match (n)-[r]->(m) return n,labels(n),collect([m.id, r, type(r)])',
            'match (src {id: {src}.id}), (dst {id: {dst}.id})',
            'match (n {id: {id_foo}})',
            'match ()',
            'match (n:`F oo`:A {a: \'ba r\', b: 0}), (m {c: 0})',
            'match (n), ()-[r]-()',
            'match ()-[:A]->()',
            'match (n:`T_nMu7ktxW` {node_attr})',
            'match (n:A:B)-[r_b:Knows {a: \'0\'}]-(m:Skill), (n)-[]-(m)',

            # path quantifier
            'match (n:A)-[r:B*0..4]-(m)',
            'match (m)-[*0..2]-(m)',
            'match ()-[r*0..6]-()',

            #
            # UNICODE tests
            #
            u'create (n:א)-[r:ב]->(m:ג:ד)',
            u'create ({א: 0})',
            u'create ({א: 0, נ: \'ערך ב\'})',
        ]
        # exp_set = []
        for clause in exp_set:
            pt = parser.parse_expression(clause)
            validate_parse_tree(pt, clause)
            valid_exp_set += [clause]

        #
        # parse all db ops
        #
        test_label = neo4j_test_util.rand_label()
        op_set = self.gen_full_db_op_set(test_label)
        # op_set = []

        for op in op_set:
            if isinstance(op, DB_composed_op):
                continue  # validated through sub-ops
            for _idx, db_q, _db_q_result in op.iter__r_set():
                q_str = db_q.q_str
                validate_parse_tree(db_q.pt_root, q_str)
                valid_exp_set += [q_str]

        self.log.debug('-' * 80 + '\npassed expression count: %d:\n\n%s' %
                       (len(valid_exp_set), '\n'.join(valid_exp_set)))
コード例 #21
0
ファイル: test_neo4j_cypher.py プロジェクト: yuvadm/rhizi
    def test_cypher_exp_parsing(self):

        def validate_parse_tree(pt, q_str):
            self.log.debug('\n'.join([' q: %s' % (q_str),
                                      'q\': %s' % (pt.str__cypher_query()),
                                      'struct: \n%s' % (pt.str__struct_tree()),
                                      ]))

            if pt.str__cypher_query() != q_str:  # test for precise query string match
                self.fail()

        valid_exp_set = []
        #
        # parse expression set
        #
        parser = Cypher_Parser()
        exp_set = [
                   'create (n:A)-[r:B]->(m:C:D), ({a: 0, b: \'b\'})',
                   'match (n) with n order by n.id skip 0 limit 2 optional match (n)-[r]->(m) return n,labels(n),collect([m.id, r, type(r)])',
                   'match (src {id: {src}.id}), (dst {id: {dst}.id})',
                   'match (n {id: {id_foo}})',
                   'match ()',
                   'match (n:`F oo`:A {a: \'ba r\', b: 0}), (m {c: 0})',
                   'match (n), ()-[r]-()',
                   'match ()-[:A]->()',
                   'match (n:`T_nMu7ktxW` {node_attr})',
                   'match (n:A:B)-[r_b:Knows {a: \'0\'}]-(m:Skill), (n)-[]-(m)',

                   # path quantifier
                   'match (n:A)-[r:B*0..4]-(m)',
                   'match (m)-[*0..2]-(m)',
                   'match ()-[r*0..6]-()',

                   #
                   # UNICODE tests
                   #
                   u'create (n:א)-[r:ב]->(m:ג:ד)',
                   u'create ({א: 0})',
                   u'create ({א: 0, נ: \'ערך ב\'})',
                   ]
        # exp_set = []
        for clause in exp_set:
            pt = parser.parse_expression(clause)
            validate_parse_tree(pt, clause)
            valid_exp_set += [clause]

        #
        # parse all db ops
        #
        test_label = neo4j_test_util.rand_label()
        op_set = self.gen_full_db_op_set(test_label)
        # op_set = []

        for op in op_set:
            if isinstance(op, DB_composed_op): continue  # validated through sub-ops
            for _idx, db_q, _db_q_result in op.iter__r_set():
                q_str = db_q.q_str
                validate_parse_tree(db_q.pt_root, q_str)
                valid_exp_set += [q_str]

        self.log.debug('-' * 80 + '\npassed expression count: %d:\n\n%s' % (len(valid_exp_set),
                                                                          '\n'.join(valid_exp_set)))
コード例 #22
0
    def test_diff_commit__topo(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_2, n_2_id = generate_random_node_dict(test_label)

        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)
        l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id)

        n_set = [n_0, n_1, n_2]
        l_set = [l_0, l_1]
        topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set)

        # commit diff
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)

        # test return type
        self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_add'))
        self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_add'))
        self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_rm'))
        self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_rm'))

        # test return set lengths
        self.assertEqual(len(ret_topo_diff.node_id_set_add), len(n_set))
        self.assertEqual(len(ret_topo_diff.link_id_set_add), len(l_set))
        self.assertEqual(len(ret_topo_diff.node_id_set_rm), 0)
        self.assertEqual(len(ret_topo_diff.link_id_set_rm), 0)

        # assert nodes persisted
        id_set = self.db_ctl.exec_op(
            DBO_match_node_set_by_id_attribute([n_0_id, n_1_id]))
        self.assertEqual(len(id_set), 2)

        # assert links persisted
        l_ptr_0 = Link.link_ptr(src_id=n_0_id, dst_id=n_1_id)
        l_ptr_1 = Link.link_ptr(src_id=n_0_id, dst_id=n_2_id)
        op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 2)

        # remova links
        topo_diff = Topo_Diff(link_id_set_rm=[l_0_id, l_1_id])
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_topo_diff.link_id_set_rm), 2)

        # assert links removed
        op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 0)

        # removal nodes
        topo_diff = Topo_Diff(node_id_set_rm=[n_2_id])
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_topo_diff.node_id_set_rm), 1)

        # assert nodes removed
        op = DBO_match_node_set_by_id_attribute([n_2_id])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 0)
コード例 #23
0
ファイル: test_db_controller.py プロジェクト: shlomif/rhizi
    def test_diff_commit__topo(self):
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        n_2, n_2_id = generate_random_node_dict(test_label)

        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)
        l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id)

        n_set = [n_0, n_1, n_2]
        l_set = [l_0, l_1]
        topo_diff = Topo_Diff(node_set_add=n_set,
                              link_set_add=l_set)

        # commit diff
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)

        # test return type
        self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_add'))
        self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_add'))
        self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_rm'))
        self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_rm'))

        # test return set lengths
        self.assertEqual(len(ret_topo_diff.node_id_set_add), len(n_set))
        self.assertEqual(len(ret_topo_diff.link_id_set_add), len(l_set))
        self.assertEqual(len(ret_topo_diff.node_id_set_rm), 0)
        self.assertEqual(len(ret_topo_diff.link_id_set_rm), 0)

        # assert nodes persisted
        id_set = self.db_ctl.exec_op(DBO_match_node_set_by_id_attribute([n_0_id, n_1_id]))
        self.assertEqual(len(id_set), 2)

        # assert links persisted
        l_ptr_0 = Link.link_ptr(src_id=n_0_id, dst_id=n_1_id)
        l_ptr_1 = Link.link_ptr(src_id=n_0_id, dst_id=n_2_id)
        op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 2)

        # remova links
        topo_diff = Topo_Diff(link_id_set_rm=[l_0_id, l_1_id])
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_topo_diff.link_id_set_rm), 2)

        # assert links removed
        op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 0)

        # removal nodes
        topo_diff = Topo_Diff(node_id_set_rm=[n_2_id])
        op = DBO_diff_commit__topo(topo_diff)
        ret_topo_diff = self.db_ctl.exec_op(op)
        self.assertEqual(len(ret_topo_diff.node_id_set_rm), 1)

        # assert nodes removed
        op = DBO_match_node_set_by_id_attribute([n_2_id])
        id_set = self.db_ctl.exec_op(op)
        self.assertEqual(len(id_set), 0)