Skip to content

Commit

Permalink
Merge pull request #794 from neo4j-contrib/bug/781-inspect-multiple-rels
Browse files Browse the repository at this point in the history
neomodel_inspect_database multiple rels for label
  • Loading branch information
mariusconjeaud authored May 13, 2024
2 parents cf2c22a + 982114b commit 47f1665
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions neomodel/scripts/neomodel_inspect_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_":
Expand Down
1 change: 1 addition & 0 deletions test/data/neomodel_inspect_database_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions test/data/neomodel_inspect_database_output_light.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions test/data/neomodel_inspect_database_output_pre_5_7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions test/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 47f1665

Please sign in to comment.