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)'
Exemple #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))
    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
    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
Exemple #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))
    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
Exemple #7
0
    def test_not_empty_nodes_fetch(self, mocker, neo4j_graph):
        query = graphic.node().query.limit(5)

        with mocker.patch.object(FakeNeo4jDriver, 'run', create=True):
            neo4j_graph.fetch(query)
            neo4j_graph._driver.run.assert_called_once_with(
                neo4j_graph.compile(query)
            )
Exemple #8
0
def new_geek_node(name):
    global gid

    gid += 1
    return graphic.node('Geek', name=name, uid=gid)._as(name.replace(' ', ''))
Exemple #9
0
def new_company_node(name):
    global cid

    cid += 1
    return graphic.node('Company', name=name,
                        cid=cid)._as(name.replace(' ', ''))
Exemple #10
0
        relationships.append(
            graphic.relationship(geek, company,
                                 type='WORKAT')._as('r{}{}'.format(
                                     geek.uid, company.cid)))
    return relationships


graph = graphic.use_neo4j()

if sys.version_info.minor == 4:
    graph.push(*company_nodes)
    graph.push(*geek_nodes)
    graph.push(*build_relations(20))
else:
    graph.push(*company_nodes, *geek_nodes, *build_relations(20))  # noqa

query = graphic.relationship(
    graphic.node('Geek')._as('g'),
    graphic.node('Company')._as('c')).query.limit(30)
result = graph.fetch(query)

local_graph = result.graph

assert len(local_graph.relationships) == 20

for node in local_graph.nodes:
    print(node)

for relation in local_graph.relationships:
    print(relation)
Exemple #11
0
 def test_empty_nodes_fetch(self, neo4j_graph):
     query = graphic.node().query.limit(0)
     result = neo4j_graph.fetch(query)
     assert result.graph.is_empty()
     assert neo4j_graph._driver is None