Exemplo n.º 1
0
    def test_nodes_create_with_duplicate_node(self):
        nodes = [
            graphic.node('Boss')._as('chuter'),
            graphic.node('Boss')._as('chuter')
        ]
        cypher = build_create_cypher(nodes)

        assert cypher == 'CREATE (chuter:Boss)'
Exemplo n.º 2
0
 def test_only_nodes_push(self, mocker, neo4j_graph):
     nodes = [
         graphic.node('Boss')._as('chuter'),
         graphic.node('Boss', uid=1234)._as('saras'),
         graphic.node('Boss', uid=1234, name="robert")._as('robert')
     ]
     with mocker.patch.object(FakeNeo4jDriver, 'run', create=True):
         neo4j_graph.push(*nodes)
         neo4j_graph._driver.run.assert_called_once_with(
             build_create_cypher(nodes))
Exemplo n.º 3
0
    def test_nodes_and_relationships_create(self):
        chuter = graphic.node('Boss')._as('chuter')
        saras = graphic.node('Boss')._as('saras')

        relationships = [
            graphic.relationship(chuter, saras, type='TALKTO')._as('cs')
        ]
        cypher = build_create_cypher([chuter, saras], relationships)

        assert cypher.find('CREATE (chuter:Boss)') >= 0
        assert cypher.find('CREATE (saras:Boss)') >= 0
        assert cypher.find('CREATE (chuter)-[cs:TALKTO]->(saras)') >= 0
Exemplo n.º 4
0
    def test_only_nodes_create(self):
        nodes = [
            graphic.node('Boss')._as('chuter'),
            graphic.node('Boss', uid=1234)._as('saras'),
            graphic.node('Boss', uid=1234, name="robert")._as('robert')
        ]
        cypher = build_create_cypher(nodes)

        assert cypher.find('CREATE (chuter:Boss)') >= 0
        assert cypher.find('CREATE (saras:Boss {uid:1234})') >= 0
        assert cypher.find(
            'CREATE (robert:Boss {uid:1234,name:"robert"})'
        ) >= 0 or cypher.find(
            'CREATE (robert:Boss {name:"robert",uid:1234})') >= 0
Exemplo n.º 5
0
    def test_nodes_and_relationships_push(self, mocker, neo4j_graph):
        chuter = graphic.node('Boss')._as('chuter')
        saras = graphic.node('Boss')._as('saras')
        robert = graphic.node('Geak')._as('robert')

        relation_ships = [
            graphic.relationship(chuter, saras, type='TALKTO')._as('cs'),
            graphic.relationship(chuter,
                                 robert,
                                 type='TALKTO',
                                 timestamp=1234660)._as('cr')
        ]

        with mocker.patch.object(FakeNeo4jDriver, 'run', create=True):
            neo4j_graph.push(chuter, *relation_ships)
            neo4j_graph._driver.run.assert_called_once_with(
                build_create_cypher([chuter, saras, robert], relation_ships))
Exemplo n.º 6
0
    def test_relationships_create_with_duplicate(self):
        chuter = graphic.node('Boss')._as('chuter')
        saras = graphic.node('Boss')._as('saras')

        relationships = [
            graphic.relationship(chuter, saras, type='TALKTO')._as('cs'),
            graphic.relationship(chuter, saras, type='TALKTO')._as('cs')
        ]
        cypher = build_create_cypher((), relationships)

        assert cypher.find('CREATE (chuter:Boss)') >= 0
        assert cypher.find('CREATE (saras:Boss)') >= 0

        rel_pos = cypher.find('CREATE (chuter)-[cs:TALKTO]->(saras)')
        assert rel_pos > 0
        assert cypher.find('CREATE (chuter)-[cs:TALKTO]->(saras)',
                           rel_pos + 1) == -1
Exemplo n.º 7
0
    def push(self, *graph_entities):
        """
        Add nodes, relationships to the neo4j server instance

        It first deal with all the nodes, then all the relationships,
        """
        # TODO(chuter):
        #   0. add path surpport
        #   1. auto covert create to merge to avoid duplicate!!!
        #   2. auto build alias for each entity whichout one
        _nodes = []
        _relationships = []

        for ent in graph_entities:
            if ent.is_node():
                _nodes.append(ent)
            if ent.is_edge():
                _relationships.append(ent)

        if len(_nodes) == 0:
            return Result(DummyEmptyGraphProxy())

        cypher_query = build_create_cypher(_nodes, _relationships)
        return Result(self._run(cypher_query))
Exemplo n.º 8
0
 def test_empty_nodes_create(self):
     cypher = build_create_cypher(())
     assert cypher == ''