Example #1
0
    def test_relationshipset_csv_create(self, graph, clear_graph,
                                        neo4j_import_dir):

        # create the nodes required here
        ns1 = NodeSet(['Test', 'Other'], merge_keys=['uuid', 'numerical'])
        ns2 = NodeSet(['Foo', 'SomeLabel'], merge_keys=['uuid', 'value'])

        for i in range(20):
            ns1.add_node({'uuid': i, 'numerical': 1})
            ns2.add_node({'uuid': i, 'value': 'foo'})

        ns1.create_index(graph)
        ns1.create(graph)
        ns2.create_index(graph)
        ns2.create(graph)

        rs = RelationshipSet('TEST', ['Test', 'Other'], ['Foo', 'SomeLabel'],
                             ['uuid', 'numerical'], ['uuid', 'value'])
        rs.uuid = 'peter'
        rs.create_index(graph)

        for i in range(10):
            rs.add_relationship({
                'uuid': i,
                'numerical': 1
            }, {
                'uuid': i,
                'value': 'foo'
            }, {
                'value': i,
                'other_value': 'peter'
            })

        # add a few relationships with different props
        for i in range(10, 20):
            rs.add_relationship({
                'uuid': i,
                'numerical': 1
            }, {
                'uuid': i,
                'value': 'foo'
            }, {
                'second_value': i,
                'other_second_value': 'peter'
            })

        path = rs.to_csv(neo4j_import_dir)

        # note: this is a hack to copy files into a running Docker container from Python
        # needed to run the tests without too many changes locally and in GitHub Actions
        copy_to_all_docker_containers(path, '/var/lib/neo4j/import')

        query = rs.csv_query('CREATE')

        graph.run(query)

        result = graph.run(
            "MATCH (source:Test:Other)-[r:TEST]->(target:Foo:SomeLabel) RETURN r"
        ).data()
        assert len(result) == len(rs.relationships)
Example #2
0
def create_nodes_test(graph, clear_graph):
    ns1 = NodeSet(['Test'], merge_keys=['uuid'])
    ns2 = NodeSet(['Foo'], merge_keys=['uuid'])

    for i in range(100):
        ns1.add_node({'uuid': i})
        ns2.add_node({'uuid': i})

    ns1.create(graph)
    ns2.create(graph)

    return ns1, ns2