diff --git a/test/data/schema.py b/test/data/schema.py index db7398f9e83b5554a6b88d55e0f6706eaae7a90d_dGVzdC9kYXRhL3NjaGVtYS5weQ==..d02ad6785eb92229c03a4047fa0bd091f4c37dcb_dGVzdC9kYXRhL3NjaGVtYS5weQ== 100644 --- a/test/data/schema.py +++ b/test/data/schema.py @@ -76,6 +76,17 @@ composite = 'subject' +class Comment(EntityType): + """A comment comments things""" + + +class comments(RelationDefinition): + subject = 'Comment' + object = ('Comment', 'Anecdote') + composite = 'object' + cardinality = '1*' + + class Group(EntityType): """A collection of individual agents""" diff --git a/test/test_compound.py b/test/test_compound.py index db7398f9e83b5554a6b88d55e0f6706eaae7a90d_dGVzdC90ZXN0X2NvbXBvdW5kLnB5..d02ad6785eb92229c03a4047fa0bd091f4c37dcb_dGVzdC90ZXN0X2NvbXBvdW5kLnB5 100644 --- a/test/test_compound.py +++ b/test/test_compound.py @@ -43,6 +43,17 @@ rels = list(graph.parent_relations('OnlineAccount')) self.assertEqual(rels, [(('account', 'object'), ['Agent'])]) + def test_parent_relations_comment(self): + graph = CompositeGraph(self.schema) + rels = list(graph.parent_relations('Comment')) + self.assertEqual(rels, [(('comments', 'subject'), + ['Comment', 'Anecdote'])]) + + def test_child_relations_comment(self): + graph = CompositeGraph(self.schema) + rels = list(graph.child_relations('Comment')) + self.assertEqual(rels, [(('comments', 'object'), ['Comment'])]) + def test_child_relations_singleton(self): graph = CompositeGraph(self.schema) rels = list(graph.child_relations('OnlineAccount')) @@ -73,8 +84,11 @@ ('event', 'object'): ['Biography'], ('narrated_by', 'subject'): ['Agent'], }, + 'Comment': { + ('comments', 'subject'): ['Anecdote', 'Comment'], + }, } self.assertEqual(structure, expected) def test_parent_structure_anecdote(self): graph = CompositeGraph(self.schema) @@ -76,11 +90,10 @@ } self.assertEqual(structure, expected) def test_parent_structure_anecdote(self): graph = CompositeGraph(self.schema) - self.set_description('Anecdote') structure = graph.parent_structure('Anecdote') expected = { 'Event': { ('relates', 'object'): ['Anecdote'], }, @@ -82,8 +95,11 @@ structure = graph.parent_structure('Anecdote') expected = { 'Event': { ('relates', 'object'): ['Anecdote'], }, + 'Comment': { + ('comments', 'subject'): ['Anecdote', 'Comment'], + } } self.assertEqual(structure, expected) @@ -109,6 +125,8 @@ anecdote1 = cnx.create_entity('Anecdote', reverse_event=bio) anecdote2 = cnx.create_entity('Anecdote', reverse_event=bio, narrated_by=agent, relates=event) + comment1 = cnx.create_entity('Comment', comments=anecdote1) + comment2 = cnx.create_entity('Comment', comments=comment1) cnx.commit() self.set_description('OnlineAccount') entities_graph = list(graph.parent_related(account)) @@ -118,7 +136,7 @@ yield self.assertCountEqual, entities_graph, expected self.set_description('Anecdote') entities_graph = list(graph.parent_related(anecdote1)) - expected = [ + anecdote1_expected = expected = [ (anecdote1, ('event', 'object'), bio), (bio, ('biography', 'object'), agent), ] @@ -132,7 +150,14 @@ (bio, ('biography', 'object'), agent), (anecdote2, ('narrated_by', 'subject'), agent), ] - self.assertCountEqual(entities_graph, expected) + yield self.assertCountEqual, entities_graph, expected + self.set_description('Comment') + entities_graph = list(graph.parent_related(comment2)) + expected = [ + (comment2, ('comments', 'subject'), comment1), + (comment1, ('comments', 'subject'), anecdote1), + ] + anecdote1_expected + yield self.assertCountEqual, entities_graph, expected def test_child_related_singleton(self): graph = CompositeGraph(self.schema) @@ -151,6 +176,8 @@ anecdote1 = cnx.create_entity('Anecdote', reverse_event=bio) anecdote2 = cnx.create_entity('Anecdote', reverse_event=bio, narrated_by=agent, relates=event) + comment1 = cnx.create_entity('Comment', comments=anecdote1) + comment2 = cnx.create_entity('Comment', comments=comment1) cnx.commit() self.set_description('Anecdote') entities_graph = list(graph.child_related(anecdote2)) @@ -154,7 +181,7 @@ cnx.commit() self.set_description('Anecdote') entities_graph = list(graph.child_related(anecdote2)) - expected = [ + expected = anecdote2_expected = [ (anecdote2, ('relates', 'subject'), event), ] yield self.assertCountEqual, entities_graph, expected @@ -158,7 +185,14 @@ (anecdote2, ('relates', 'subject'), event), ] yield self.assertCountEqual, entities_graph, expected + self.set_description('Anecdote (1)') + entities_graph = list(graph.child_related(anecdote1)) + expected = anecdote1_expected = [ + (anecdote1, ('comments', 'object'), comment1), + (comment1, ('comments', 'object'), comment2), + ] + yield self.assertCountEqual, entities_graph, expected self.set_description('Agent') entities_graph = list(graph.child_related(agent)) expected = [ (agent, ('account', 'subject'), account), @@ -161,10 +195,9 @@ self.set_description('Agent') entities_graph = list(graph.child_related(agent)) expected = [ (agent, ('account', 'subject'), account), - (agent, ('biography', 'subject'), bio), (bio, ('event', 'subject'), event), (bio, ('event', 'subject'), anecdote1), (bio, ('event', 'subject'), anecdote2), (agent, ('narrated_by', 'object'), anecdote2), @@ -166,10 +199,9 @@ (agent, ('biography', 'subject'), bio), (bio, ('event', 'subject'), event), (bio, ('event', 'subject'), anecdote1), (bio, ('event', 'subject'), anecdote2), (agent, ('narrated_by', 'object'), anecdote2), - (anecdote2, ('relates', 'subject'), event), - ] + ] + anecdote2_expected + anecdote1_expected yield self.assertCountEqual, entities_graph, expected @@ -184,7 +216,8 @@ ('narrated_by', 'object')], 'Event': [], 'Biography': [('event', 'subject')], - 'Anecdote': [('relates', 'subject')], + 'Anecdote': [('comments', 'object'), ('relates', 'subject')], + 'Comment': [('comments', 'object')], } self.assertEqual(defn, expected)