def test_bind_exc_handler__first(app): assert 'exc_handlers' not in app handler = Mock(name='handler') bind_exc_handler(app, RuntimeError, handler) assert 'exc_handlers' in app assert app['exc_handlers'][RuntimeError] == handler
def test_bind_exc_handler__exists(app): app['exc_handlers'] = {ValueError: 'handler_old'} handler = Mock(name='handler') bind_exc_handler(app, RuntimeError, handler) assert app['exc_handlers'][RuntimeError] == handler assert app['exc_handlers'][ValueError] == 'handler_old'
def bind_view(self, resource, view, tail=()): """ Bind view to resource. """ if not self.active: raise RuntimeError("configure process is not active") log.debug("bind_view: {mod}, {res}{tail} -> {view}" "".format( mod=self._include_module or '__main__', res=resource.__name__, tail=tail if isinstance(tail, str) else '/'.join(tail), view=view.__name__, )) if issubclass(resource, Exception): if tail: raise TypeError("tail not accepted for exception resources") bind_exc_handler(self.app, resource, view) else: self.app.router.bind_view(resource, view, tail)
def test_bind_exc_handler__middleware_not_exist(app): app._middlewares.clear() with pytest.raises(RuntimeError): bind_exc_handler(app, ValueError, Mock(name='handler'))