Ejemplo n.º 1
0
    def test_add_to_app(self, _import_module):
        _import_module.return_value = mock.MagicMock(urls=self.routes)

        route = Include('foo.bar', routes_name='urls')
        route.add_to_app(self.app)

        self.assertEqual(url_for('foo'), '/foo')
        self.assertEqual(url_for('bar'), '/bar')
Ejemplo n.º 2
0
    def test_add_to_app(self, _import_module):
        _import_module.return_value = mock.MagicMock(urls=self.routes)

        route = Include('foo.bar', routes_name='urls')
        route.add_to_app(self.app)

        self.assertEqual(url_for('foo'), '/foo')
        self.assertEqual(url_for('bar'), '/bar')
Ejemplo n.º 3
0
    def test_add_to_app(self, import_module):
        routes = [
            mock.MagicMock(),
            mock.MagicMock()
        ]
        import_module.return_value = mock.MagicMock(urls=routes)

        route = Include('foo.bar', routes_name='urls')
        route.add_to_app(self.app)

        for instance in routes:
            instance.add_to_app.assert_called_once_with(self.app)
Ejemplo n.º 4
0
    def test_endpoint_prefix(self, _import_module):
        routes1 = copy.deepcopy(self.routes)
        routes1.append(Include('foo.bar', endpoint='endpoint2'))
        routes2 = copy.deepcopy(self.routes)

        _import_module.side_effect = [
            mock.MagicMock(routes=routes1),
            mock.MagicMock(routes=routes2)
        ]

        include = Include('foo.bar', endpoint='endpoint1')
        include.add_to_app(self.app)

        self.assertEqual(url_for('endpoint1.foo'), '/foo')
        self.assertEqual(url_for('endpoint1.bar'), '/bar')
        self.assertEqual(url_for('endpoint1.endpoint2.foo'), '/foo')
        self.assertEqual(url_for('endpoint1.endpoint2.bar'), '/bar')
Ejemplo n.º 5
0
    def test_endpoint_prefix(self, _import_module):
        routes1 = copy.deepcopy(self.routes)
        routes1.append(Include(
            'foo.bar',
            endpoint='endpoint2'))
        routes2 = copy.deepcopy(self.routes)

        _import_module.side_effect = [
            mock.MagicMock(routes=routes1),
            mock.MagicMock(routes=routes2)
        ]

        include = Include('foo.bar', endpoint='endpoint1')
        include.add_to_app(self.app)

        self.assertEqual(url_for('endpoint1.foo'), '/foo')
        self.assertEqual(url_for('endpoint1.bar'), '/bar')
        self.assertEqual(url_for('endpoint1.endpoint2.foo'), '/foo')
        self.assertEqual(url_for('endpoint1.endpoint2.bar'), '/bar')
Ejemplo n.º 6
0
    def test_init(self):
        route = Include('foo.bar', routes_name='urls')

        self.assertEqual(route.routes_module, 'foo.bar')
        self.assertEqual(route.routes_name, 'urls')