def test_add_expansion_merges_children(self): expansion_node = ExpansionNode( node_type='bar', name='bar', source_field='bar_id', destination_field='bar', service='bar', action='get_bar', request_field='id', response_field='bar', ) self.type_node.add_expansion(expansion_node) another_expansion_node = ExpansionNode( node_type='bar', name='bar', source_field='bar_id', destination_field='bar', service='bar', action='get_bar', request_field='id', response_field='bar', ) child_expansion_node = ExpansionNode( node_type='baz', name='baz', source_field='baz_id', destination_field='baz', service='baz', action='get_baz', request_field='id', response_field='baz', ) another_expansion_node.add_expansion(child_expansion_node) self.type_node.add_expansion(another_expansion_node) self.assertEqual(len(self.type_node.expansions), 1) self.assertNotEqual( self.type_node.expansions[0], another_expansion_node, ) self.assertEqual( len(self.type_node.expansions[0].expansions), 1, ) self.assertEqual( self.type_node.expansions[0].expansions[0], child_expansion_node, )
class TestExpansionNode(TestCase): def setUp(self): self.expansion_node = ExpansionNode( node_type='foo', name='foo', source_field='foo_id', destination_field='foo', service='foo', action='get_foo', request_field='id', response_field='foo', ) def test_to_strings_with_expansions(self): bar_expansion_node = ExpansionNode( node_type='bar', name='bar', source_field='bar_id', destination_field='bar', service='bar', action='get_bar', request_field='id', response_field='bar', ) baz_expansion_node = ExpansionNode( node_type='baz', name='baz', source_field='baz_id', destination_field='baz', service='baz', action='get_baz', request_field='id', response_field='baz', ) self.expansion_node.add_expansion(bar_expansion_node) self.expansion_node.add_expansion(baz_expansion_node) self.assertEqual( set(self.expansion_node.to_strings()), {'foo.baz', 'foo.bar'}, ) def test_to_strings_without_expansions(self): self.assertEqual( self.expansion_node.to_strings(), ['foo'], )
def test_to_dict(self): bar_expansion_node = ExpansionNode( node_type='bar', name='bar', source_field='bar_id', destination_field='bar', service='bar', action='get_bar', request_field='id', response_field='bar', ) baz_expansion_node = ExpansionNode( node_type='baz', name='baz', source_field='baz_id', destination_field='baz', service='baz', action='get_baz', request_field='id', response_field='baz', ) qux_expansion_node = ExpansionNode( node_type='qux', name='qux', source_field='qux_id', destination_field='qux', service='qux', action='get_qux', request_field='id', response_field='qux', ) bar_expansion_node.add_expansion(baz_expansion_node) bar_expansion_node.add_expansion(qux_expansion_node) self.type_node.add_expansion(bar_expansion_node) type_node_dict = self.type_node.to_dict() self.assertTrue('foo' in type_node_dict) self.assertEqual(set(type_node_dict['foo']), {'bar.qux', 'bar.baz'})