|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +# Copyright (c) 2002-2020 "Neo4j," |
| 5 | +# Neo4j Sweden AB [http://neo4j.com] |
| 6 | +# |
| 7 | +# This file is part of Neo4j. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | + |
| 21 | + |
| 22 | +import pytest |
| 23 | + |
| 24 | +from neo4j.graph import ( |
| 25 | + Node, |
| 26 | + Relationship, |
| 27 | + Graph, |
| 28 | + Path, |
| 29 | +) |
| 30 | +from neo4j.exceptions import Neo4jError |
| 31 | + |
| 32 | + |
| 33 | +def test_result_graph_instance(session): |
| 34 | + # python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_instance |
| 35 | + result = session.run("RETURN 1") |
| 36 | + graph = result.graph() |
| 37 | + |
| 38 | + assert isinstance(graph, Graph) |
| 39 | + |
| 40 | + |
| 41 | +def test_result_graph_case_1(session): |
| 42 | + # python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_case_1 |
| 43 | + result = session.run("CREATE (n1:Person:LabelTest1 {name:'Alice'})-[r1:KNOWS {since:1999}]->(n2:Person:LabelTest2 {name:'Bob'}) RETURN n1, r1, n2") |
| 44 | + graph = result.graph() |
| 45 | + assert isinstance(graph, Graph) |
| 46 | + |
| 47 | + node_view = graph.nodes |
| 48 | + relationships_view = graph.relationships |
| 49 | + |
| 50 | + for node in node_view: |
| 51 | + name = node["name"] |
| 52 | + if name == "Alice": |
| 53 | + assert node.labels == frozenset(["Person", "LabelTest1"]) |
| 54 | + elif name == "Bob": |
| 55 | + assert node.labels == frozenset(["Person", "LabelTest2"]) |
| 56 | + else: |
| 57 | + pytest.fail("should only contain 2 nodes, Alice and Bob. {}".format(name)) |
| 58 | + |
| 59 | + for relationship in relationships_view: |
| 60 | + since = relationship["since"] |
| 61 | + assert since == 1999 |
| 62 | + assert relationship.type == "KNOWS" |
0 commit comments