Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neomodel_inspect_database multiple rels for label #794

Merged
merged 2 commits into from
May 13, 2024
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
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
Loading