def testListCLI(self): """ Test that we can list clis, get help for each, and get the xml spec for each. """ from girder.plugins.slicer_cli_web import rest_slicer_cli from girder.api.rest import Resource restResource = Resource() cli_args = ('--list_cli', ) cli_list = self._runTest(cli_args, contains=['"NucleiDetection"']) cli_list = json.loads(cli_list) self.assertIn('NucleiDetection', cli_list) for cli in cli_list: cli_args = (cli, '--help') # Each cli's help must mention usage, its own name, and that you # can output xml self._runTest(cli_args, contains=['usage:', cli, '--xml']) cli_args = (cli, '--xml') # The xml output needs to have a tile and an executable tag xml = self._runTest(cli_args, contains=[ '<executable>', '<title>', '</executable>', '</title>' ]) if '<' in xml: xml = xml[xml.index('<'):] try: rest_slicer_cli.genHandlerToRunDockerCLI( 'dockerimage', os.environ.get('CLI_CWD'), xml, restResource) except Exception: sys.stderr.write('Failed in generating endpoints for %s' % cli) raise
def load(self, info): info['apiRoot'].configuration = Configuration() # Twitter and orcid stuff info['apiRoot'].user.route('GET', (':id', 'orcid'), get_orcid) info['apiRoot'].user.route('POST', (':id', 'orcid'), set_orcid) info['apiRoot'].user.route('GET', (':id', 'twitter'), get_twitter) info['apiRoot'].user.route('POST', (':id', 'twitter'), set_twitter) # Launch a taskflow with a single endpoint info['apiRoot'].launch_taskflow = Resource() info['apiRoot'].launch_taskflow.route('POST', ('launch', ), launch_taskflow_endpoint)
def testRouteSystem(self): # Test an empty route handler emptyResource = Resource() self.assertRaises(GirderException, emptyResource.handleRoute, 'GET', (), {}) dummy = DummyResource() # Bad route should give a useful exception. exc = None try: dummy.handleRoute('GET', (), {}) except RestException as e: exc = e.message self.assertEqual(exc, 'No matching route for "GET "') # Make sure route ordering is correct; literals before wildcard tokens r = dummy.handleRoute('GET', ('literal1', 'foo'), {}) self.assertEqual(r, {'wc1': 'literal1', 'wc2': 'foo', 'params': {}}) r = dummy.handleRoute('GET', ('literal1', 'literal2'), {}) self.assertEqual(r, {'params': {}}) r = dummy.handleRoute('PATCH', ('guid', 'patchy'), {}) self.assertEqual(r, {'id': 'guid', 'params': {}}) # Add a new route with a new method dummy.route('DUMMY', (':id', 'dummy'), dummy.handler) r = dummy.handleRoute('DUMMY', ('guid', 'dummy'), {}) self.assertEqual(r, {'id': 'guid', 'params': {}}) # Test getting the route handler self.assertRaises(Exception, dummy.getRouteHandler, 'FOO', (':id', 'dummy')) self.assertRaises(Exception, dummy.getRouteHandler, 'DUMMY', (':id', 'foo')) registeredHandler = dummy.getRouteHandler('DUMMY', (':id', 'dummy')) # The handler method cannot be compared directly with `is`, but its name and behavior can be # examined self.assertEqual(registeredHandler.__name__, dummy.handler.__name__) self.assertEqual(registeredHandler(foo=42), {'foo': 42}) # Now remove the route dummy.removeRoute('DUMMY', (':id', 'dummy')) self.assertRaises(RestException, dummy.handleRoute, 'DUMMY', ('guid', 'dummy'), {})