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)
def test_nodeset_recreate_existing_single_index(self, graph, clear_graph): """ The output/error when you try to recreate an existing index is different in Neo4j 3.5 and 4. Create an index a few times to make sure this error is handled. """ labels = ['TestNode'] properties = ['some_key'] ns = NodeSet(labels, merge_keys=properties) ns.create_index(graph) ns.create_index(graph) ns.create_index(graph)
def test_nodeset_create_composite_index(self, graph, clear_graph): labels = ['TestNode'] properties = ['some_key', 'other_key'] ns = NodeSet(labels, merge_keys=properties) ns.create_index(graph) result = list(graph.run("CALL db.indexes()")) for row in result: # the result of the db.indexes() procedure is different for Neo4j 3.5 and 4 # this should also be synced with differences in py2neo versions if 'tokenNames' in row: assert row['tokenNames'] == labels and row['properties'] == properties \ or row['tokenNames'] == labels and row['properties'] == properties elif 'labelsOrTypes' in row: assert row['labelsOrTypes'] == labels and row['properties'] == properties \ or row['labelsOrTypes'] == labels and row['properties'] == properties