def test_all_dispatchers(self): for service in SUPPORTED_SERVICES: disp = Dispatcher() dispatcher_module = importlib.import_module('jumpgate.' + service) dispatcher_module.add_endpoints(disp) self.assertGreater(len(disp._endpoints), 0)
def test_add_get_dispatcher(self): disp = Dispatcher() self.app.add_dispatcher('SERVICE', disp) self.assertEqual(self.app._dispatchers, {'SERVICE': disp}) disp_return = self.app.get_dispatcher('SERVICE') self.assertEqual(disp_return, disp)
def test_all_endpoints(self): for service in SUPPORTED_SERVICES: app = Jumpgate() app.config = MOCK_CONFIG disp = Dispatcher() dispatcher_module = importlib.import_module('jumpgate.' + service) dispatcher_module.add_endpoints(disp) module_name = 'jumpgate.%s.drivers.sl' % service module = importlib.import_module(module_name) module.setup_routes(app, disp) self.assertGreater(len(disp._endpoints), 0)
def load_endpoints(self): for service in SUPPORTED_SERVICES: enabled_services = self.config['enabled_services'] if service in enabled_services: service_module = importlib.import_module('jumpgate.' + service) # Import the dispatcher for the service disp = Dispatcher(mount=self.config[service]['mount']) service_module.add_endpoints(disp) self.add_dispatcher(service, disp) self.installed_modules[service] = True else: self.installed_modules[service] = False
def test_get_endpoint_url(self): disp = Dispatcher() disp.add_endpoint('user_page0', '/path0/to/{tenant_id}') self.app.add_dispatcher('SERVICE', disp) req = MagicMock() req.env = {'tenant_id': '1234'} req.protocol = 'http' req.get_header.return_value = 'some_host' req.app = '' url = self.app.get_endpoint_url('SERVICE', req, 'user_page0') self.assertEqual(url, 'http://some_host/path0/to/1234')
def test_make_api(self): # Populate a dispatcher with some resources disp = Dispatcher() resources = [StubResource() for i in range(10)] for i, resource in enumerate(resources): disp.add_endpoint('test_%s' % i, '/path/to/%s' % i) disp.set_handler('test_%s' % i, resource) self.app.add_dispatcher('SERVICE', disp) api = self.app.make_api() self.assertTrue(hasattr(api, '__call__')) self.assertIsInstance(api, falcon.API) self.assertEqual(len(api._routes), 20)
def setUp(self): self.disp = Dispatcher(mount='/mountpoint')
def setUp(self): self.disp = Dispatcher() self.disp.add_endpoint('user_page', '/path/to/{tenant_id}') self.disp.add_endpoint('instance_detail', '/path/to/{tenant_id}/{instance_id}')