def execute(self): try: router = self.container.get('router') if not router.routes: raise ConsoleError('There are no routes associated with the application.') if self.parsed_args.url: environ = {} util.setup_testing_defaults(environ) environ.update({ 'REQUEST_METHOD': self.parsed_args.method or 'GET', 'HTTP_ACCEPT': self.parsed_args.format or 'text/html', 'PATH_INFO': self.parsed_args.url, 'SERVER_NAME': self.parsed_args.server or '127.0.0.1' }) request = create_request_from_environ(environ) matches = router.matches(request) if matches: sys.stdout.write(colors.header('Displaying {0} matching routes for the application:\n'.format(len(matches)))) for match in matches: sys.stdout.write('{0}\t\t\{1}\t\t{2}\n'.format(colors.ok_green(match.route.name), match.route.path, match.route.regex.pattern)) else: raise ConsoleError('There are no matching routes.') else: sys.stdout.write(colors.header('Displaying {0} routes for the application:\n'.format(len(router)))) for name, route in router: sys.stdout.write('{0}\t\t{1}\n'.format(name, route.path)) except ConsoleError: raise except: _no_application_error()
def execute(self): try: router = self.container.get('router') if not router.routes: raise ConsoleError( 'There are no routes associated with the application.') if self.parsed_args.url: environ = {} util.setup_testing_defaults(environ) environ.update({ 'REQUEST_METHOD': self.parsed_args.method or 'GET', 'HTTP_ACCEPT': self.parsed_args.format or 'text/html', 'PATH_INFO': self.parsed_args.url, 'SERVER_NAME': self.parsed_args.server or '127.0.0.1' }) request = Request.from_environ(environ) matches = router.matches(request) if matches: sys.stdout.write( colors.header( 'Displaying {0} matching routes for the application:\n' .format(len(matches)))) for match in matches: sys.stdout.write('{0}\t\t\{1}\t\t{2}\n'.format( colors.ok_green(match.route.name), match.route.path, match.route.regex.pattern)) else: raise ConsoleError('There are no matching routes.') else: sys.stdout.write( colors.header( 'Displaying {0} routes for the application:\n'.format( len(router)))) for name, route in router: sys.stdout.write('{0}\t\t{1}\n'.format(name, route.path)) except ConsoleError: raise except: _no_application_error()
def test_ok_green(self): assert ok_green('test') == '\033[92mtest\033[0m' assert ok_green('test', terminate=False) == '\033[92mtest'