Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neo4j/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def hydrate_node(self, n_id, n_labels=None, properties=None):
# a relationship, it won't have any labels or properties.
# Therefore, we need to add the ones we have here.
if n_labels:
inst._labels = frozenset(inst._labels & set(n_labels))
inst._labels = inst._labels.union(n_labels) # frozen_set
if properties:
inst._properties.update(properties)
return inst
Expand Down
62 changes: 62 additions & 0 deletions tests/integration/test_result_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

# Copyright (c) 2002-2020 "Neo4j,"
# Neo4j Sweden AB [http://neo4j.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import pytest

from neo4j.graph import (
Node,
Relationship,
Graph,
Path,
)
from neo4j.exceptions import Neo4jError


def test_result_graph_instance(session):
# python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_instance
result = session.run("RETURN 1")
graph = result.graph()

assert isinstance(graph, Graph)


def test_result_graph_case_1(session):
# python -m pytest tests/integration/test_result_graph.py -s -v -k test_result_graph_case_1
result = session.run("CREATE (n1:Person:LabelTest1 {name:'Alice'})-[r1:KNOWS {since:1999}]->(n2:Person:LabelTest2 {name:'Bob'}) RETURN n1, r1, n2")
graph = result.graph()
assert isinstance(graph, Graph)

node_view = graph.nodes
relationships_view = graph.relationships

for node in node_view:
name = node["name"]
if name == "Alice":
assert node.labels == frozenset(["Person", "LabelTest1"])
elif name == "Bob":
assert node.labels == frozenset(["Person", "LabelTest2"])
else:
pytest.fail("should only contain 2 nodes, Alice and Bob. {}".format(name))

for relationship in relationships_view:
since = relationship["since"]
assert since == 1999
assert relationship.type == "KNOWS"