Exemplo n.º 1
0
    def test_trees_to_dict(self):
        foo_tree_node = TypeNode(node_type='foo')
        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',
        )
        foo_tree_node.add_expansion(bar_expansion_node)

        baz_tree_node = TypeNode(node_type='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',
        )
        baz_tree_node.add_expansion(qux_expansion_node)

        self.assertEqual(
            self.converter.trees_to_dict([foo_tree_node, baz_tree_node]),
            {
                'foo': ['bar'],
                'baz': ['qux'],
            },
        )
Exemplo n.º 2
0
    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'},
        )
Exemplo n.º 3
0
 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',
     )
Exemplo n.º 4
0
 def test_get_expansion(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)
     self.assertEqual(
         self.type_node.get_expansion(expansion_node.name),
         expansion_node,
     )
Exemplo n.º 5
0
    def test_cannot_add_same_expansion_twice(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)
        self.type_node.add_expansion(expansion_node)

        self.assertEqual(len(self.type_node.expansions), 1)
        self.assertEqual(
            self.type_node.expansions[0],
            expansion_node,
        )
Exemplo n.º 6
0
    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,
        )
Exemplo n.º 7
0
    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'})