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_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_init(self): route = Include('foo.bar', routes_name='urls') self.assertEqual(route.routes_module, 'foo.bar') self.assertEqual(route.routes_name, 'urls')