From 212b3499b63867d53782248cc5f55d20ee6fd207 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 22 Oct 2024 16:20:11 +0200 Subject: [PATCH] Improved tests --- test/async_/test_match_api.py | 27 +++++++++++++++++++++++++-- test/sync_/test_match_api.py | 27 +++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/test/async_/test_match_api.py b/test/async_/test_match_api.py index a69b9834..81944871 100644 --- a/test/async_/test_match_api.py +++ b/test/async_/test_match_api.py @@ -25,6 +25,7 @@ AsyncTraversal, Collect, Last, + NodeNameResolver, Optional, RawCypher, RelationNameResolver, @@ -768,6 +769,19 @@ async def test_annotate_and_collect(): ) assert len(result[0][1][0]) == 2 # 2 species must be there + result = ( + await Supplier.nodes.traverse_relations("coffees__species") + .annotate( + all_species=Collect(NodeNameResolver("coffees__species"), distinct=True), + all_species_rels=Collect( + RelationNameResolver("coffees__species"), distinct=True + ), + ) + .all() + ) + assert len(result[0][1][0]) == 2 # 2 species must be there + assert len(result[0][2][0]) == 3 # 3 species relations must be there + @mark_async_test async def test_resolve_subgraph(): @@ -900,11 +914,11 @@ async def test_intermediate_transform(): await nescafe.species.connect(arabica) result = ( - await Coffee.nodes.traverse_relations(suppliers="suppliers") + await Coffee.nodes.fetch_relations("suppliers") .intermediate_transform( { "coffee": "coffee", - "suppliers": "suppliers", + "suppliers": NodeNameResolver("suppliers"), "r": RelationNameResolver("suppliers"), }, ordering=["-r.since"], @@ -927,6 +941,15 @@ async def test_intermediate_transform(): "test": Collect("suppliers"), } ) + with raises( + ValueError, + match=re.escape( + r"You must provide one variable at least when calling intermediate_transform()" + ), + ): + Coffee.nodes.traverse_relations(suppliers="suppliers").intermediate_transform( + {} + ) @mark_async_test diff --git a/test/sync_/test_match_api.py b/test/sync_/test_match_api.py index ff421a4b..e47e3396 100644 --- a/test/sync_/test_match_api.py +++ b/test/sync_/test_match_api.py @@ -23,6 +23,7 @@ from neomodel.sync_.match import ( Collect, Last, + NodeNameResolver, NodeSet, Optional, QueryBuilder, @@ -756,6 +757,19 @@ def test_annotate_and_collect(): ) assert len(result[0][1][0]) == 2 # 2 species must be there + result = ( + Supplier.nodes.traverse_relations("coffees__species") + .annotate( + all_species=Collect(NodeNameResolver("coffees__species"), distinct=True), + all_species_rels=Collect( + RelationNameResolver("coffees__species"), distinct=True + ), + ) + .all() + ) + assert len(result[0][1][0]) == 2 # 2 species must be there + assert len(result[0][2][0]) == 3 # 3 species relations must be there + @mark_sync_test def test_resolve_subgraph(): @@ -888,11 +902,11 @@ def test_intermediate_transform(): nescafe.species.connect(arabica) result = ( - Coffee.nodes.traverse_relations(suppliers="suppliers") + Coffee.nodes.fetch_relations("suppliers") .intermediate_transform( { "coffee": "coffee", - "suppliers": "suppliers", + "suppliers": NodeNameResolver("suppliers"), "r": RelationNameResolver("suppliers"), }, ordering=["-r.since"], @@ -915,6 +929,15 @@ def test_intermediate_transform(): "test": Collect("suppliers"), } ) + with raises( + ValueError, + match=re.escape( + r"You must provide one variable at least when calling intermediate_transform()" + ), + ): + Coffee.nodes.traverse_relations(suppliers="suppliers").intermediate_transform( + {} + ) @mark_sync_test