From a12def2e06d5ec2ee7e38f6c70f4f83536d1c622 Mon Sep 17 00:00:00 2001 From: Marius Conjeaud Date: Mon, 6 May 2024 10:44:03 +0200 Subject: [PATCH 1/2] Fix bug where inspect database script only returns one rel for each label --- neomodel/scripts/neomodel_inspect_database.py | 4 ++-- test/data/neomodel_inspect_database_output.txt | 1 + test/data/neomodel_inspect_database_output_light.txt | 1 + test/data/neomodel_inspect_database_output_pre_5_7.txt | 1 + test/data/neomodel_inspect_database_output_pre_5_7_light.txt | 1 + test/test_scripts.py | 3 +++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/neomodel/scripts/neomodel_inspect_database.py b/neomodel/scripts/neomodel_inspect_database.py index 3147ebdf..bb2d8452 100644 --- a/neomodel/scripts/neomodel_inspect_database.py +++ b/neomodel/scripts/neomodel_inspect_database.py @@ -126,13 +126,13 @@ def outgoing_relationships(cls, start_label, get_properties: bool = True): MATCH (n:`{start_label}`)-[r]->(m) WITH DISTINCT type(r) as rel_type, head(labels(m)) AS target_label, keys(r) AS properties, head(collect(r)) AS sampleRel ORDER BY size(properties) DESC - RETURN rel_type, target_label, apoc.meta.cypher.types(properties(sampleRel)) AS properties LIMIT 1 + RETURN DISTINCT rel_type, target_label, collect(DISTINCT apoc.meta.cypher.types(properties(sampleRel)))[0] AS properties """ else: query = f""" MATCH (n:`{start_label}`)-[r]->(m) WITH DISTINCT type(r) as rel_type, head(labels(m)) AS target_label - RETURN rel_type, target_label, {{}} AS properties LIMIT 1 + RETURN rel_type, target_label, {{}} AS properties """ result, _ = db.cypher_query(query) return [(record[0], record[1], record[2]) for record in result] diff --git a/test/data/neomodel_inspect_database_output.txt b/test/data/neomodel_inspect_database_output.txt index 8ddc9d39..3a532dd6 100644 --- a/test/data/neomodel_inspect_database_output.txt +++ b/test/data/neomodel_inspect_database_output.txt @@ -5,6 +5,7 @@ class ScriptsTestNode(StructuredNode): personal_id = StringProperty(unique_index=True) name = StringProperty(index=True) rel = RelationshipTo("ScriptsTestNode", "REL", cardinality=ZeroOrOne, model="RelRel") + other_rel = RelationshipTo("ScriptsTestNode", "OTHER_REL", cardinality=ZeroOrOne) class RelRel(StructuredRel): diff --git a/test/data/neomodel_inspect_database_output_light.txt b/test/data/neomodel_inspect_database_output_light.txt index c9adeca3..a7fd16ec 100644 --- a/test/data/neomodel_inspect_database_output_light.txt +++ b/test/data/neomodel_inspect_database_output_light.txt @@ -5,6 +5,7 @@ class ScriptsTestNode(StructuredNode): personal_id = StringProperty(unique_index=True) name = StringProperty(index=True) rel = RelationshipTo("ScriptsTestNode", "REL") + other_rel = RelationshipTo("ScriptsTestNode", "OTHER_REL") class EveryPropertyTypeNode(StructuredNode): diff --git a/test/data/neomodel_inspect_database_output_pre_5_7.txt b/test/data/neomodel_inspect_database_output_pre_5_7.txt index 8dc8e412..b025411e 100644 --- a/test/data/neomodel_inspect_database_output_pre_5_7.txt +++ b/test/data/neomodel_inspect_database_output_pre_5_7.txt @@ -5,6 +5,7 @@ class ScriptsTestNode(StructuredNode): personal_id = StringProperty(unique_index=True) name = StringProperty(index=True) rel = RelationshipTo("ScriptsTestNode", "REL", cardinality=ZeroOrOne, model="RelRel") + other_rel = RelationshipTo("ScriptsTestNode", "OTHER_REL", cardinality=ZeroOrOne) class RelRel(StructuredRel): diff --git a/test/data/neomodel_inspect_database_output_pre_5_7_light.txt b/test/data/neomodel_inspect_database_output_pre_5_7_light.txt index c9adeca3..a7fd16ec 100644 --- a/test/data/neomodel_inspect_database_output_pre_5_7_light.txt +++ b/test/data/neomodel_inspect_database_output_pre_5_7_light.txt @@ -5,6 +5,7 @@ class ScriptsTestNode(StructuredNode): personal_id = StringProperty(unique_index=True) name = StringProperty(index=True) rel = RelationshipTo("ScriptsTestNode", "REL") + other_rel = RelationshipTo("ScriptsTestNode", "OTHER_REL") class EveryPropertyTypeNode(StructuredNode): diff --git a/test/test_scripts.py b/test/test_scripts.py index 5583af47..07a5a14b 100644 --- a/test/test_scripts.py +++ b/test/test_scripts.py @@ -21,6 +21,7 @@ class ScriptsTestNode(StructuredNode): personal_id = StringProperty(unique_index=True) name = StringProperty(index=True) rel = RelationshipTo("ScriptsTestNode", "REL", model=ScriptsTestRel) + other_rel = RelationshipTo("ScriptsTestNode", "OTHER_REL") def test_neomodel_install_labels(): @@ -113,7 +114,9 @@ def test_neomodel_inspect_database(script_flavour): # Create a few nodes and a rel, with indexes and constraints node1 = ScriptsTestNode(personal_id="1", name="test").save() node2 = ScriptsTestNode(personal_id="2", name="test").save() + node3 = ScriptsTestNode(personal_id="3", name="test").save() node1.rel.connect(node2, {"some_unique_property": "1", "some_index_property": "2"}) + node1.other_rel.connect(node3) # Create a node with all the parsable property types # Also create a node with no properties From 982114be4c2e776753e2cbd821413e6d2412799b Mon Sep 17 00:00:00 2001 From: Marius Conjeaud Date: Mon, 6 May 2024 11:10:59 +0200 Subject: [PATCH 2/2] Fix test collection - was skipping test_contrib --- test/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/conftest.py b/test/conftest.py index a60302de..a97750fa 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -37,6 +37,8 @@ def pytest_collection_modifyitems(items): for item in items: # Check the directory of the item directory = item.fspath.dirname.split("/")[-1] + if directory == "test_contrib": + directory = item.fspath.dirname.split("/")[-2] if "connect_to_aura" in item.name: if directory == "async_":