def setup_class(cls):
        cls._failure_occurred = False  # flag for logging
        cls.log = get_wrapped_logger(cls.__name__)
        cls.log.handlers[0].setFormatter(
            LevelFormatter(
                fmt=('[%(levelname)1.1s '
                     '%(asctime)s.%(msecs).03d '
                     '%(name)s %(module)s:%(lineno)d]'
                     '%(message)s'),
                datefmt='%H:%M:%S',
            ))
        cls._setup_patches()
        cls.pre_server_setup()

        cls.log.info('starting webdriver')
        cls.init_webdriver()
        cls.log.info('Starting jupyterhub server app thread')
        cls.app = MockHub.instance(
            log_datefmt="%H:%M:%S",
            authenticator_class=MockAuthenticator,
            spawner_class=TestSpawner,
        )
        # need to start jupyterhub app before calling super, as the super will
        # wait for the page to load
        try:
            cls.app.log = wrap_logger_handlers(cls.app.log)
            cls.app.start([])
        except Exception:
            cls._server_cleanup(error_msg='failed to start jupyterhub app')

        try:
            cls.log.info(
                'Logging into hub-spawned single-user notebook server.')
            login_url = public_url(cls.app) + 'login'
            cls.driver.get(login_url)
            cls.uname = name = next(iter(MockAuthenticator._default_whitelist))
            cls.wait_for_selector('#username_input').send_keys(name)
            cls.wait_for_selector('#password_input').send_keys(name)
            cls.wait_for_selector('#login_submit').click()
            cls.wait_for_selector('#header')  # single-user page loaded

            user = cls.user = cls.app.users[name]
            if not user.running:
                io_loop = IOLoop()
                io_loop.make_current()
                io_loop.run_sync(user.spawn)
        except Exception:
            cls._server_cleanup(
                error_msg='failed to start/login to single-user server')
Example #2
0
 def _read_proc_stderr(self):
     logr = get_logger(self.user.name)
     logr.handlers[0].setFormatter(logging.Formatter(fmt='    %(message)s'))
     logr = wrap_logger_handlers(logr)
     for line in iter(self.proc.stdout.readline, b''):
         logr.info(line.decode('utf-8').strip('\n'))
Example #3
0
 def _log_default(self):
     """wrap loggers for this application."""
     return wrap_logger_handlers(LocalProcessSpawner._log_default(self))
Example #4
0
 def _log_default(self):
     """wrap loggers for this application."""
     return wrap_logger_handlers(Authenticator._log_default(self))