From ff063d242de584405fe92b9b664d77b47a60d5a4 Mon Sep 17 00:00:00 2001 From: martin bendsoe Date: Fri, 5 Jun 2020 17:30:34 +0200 Subject: [PATCH] fixed label issue for last node when hydrating relationship --- neo4j/graph/__init__.py | 2 +- tests/integration/test_result_graph.py | 62 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/integration/test_result_graph.py diff --git a/neo4j/graph/__init__.py b/neo4j/graph/__init__.py index 2f898ca32..95f316e86 100644 --- a/neo4j/graph/__init__.py +++ b/neo4j/graph/__init__.py @@ -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 diff --git a/tests/integration/test_result_graph.py b/tests/integration/test_result_graph.py new file mode 100644 index 000000000..9d8b9034e --- /dev/null +++ b/tests/integration/test_result_graph.py @@ -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"