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')
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)
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')
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')