def test_user_errors_non_field_specific_error() -> None: errors = UserErrors() assert not errors errors.add(MKUserError(None, "abc")) assert errors assert errors[None] == "abc"
def __init__( self, req: http.Request, resp: http.Response, funnel: OutputFunnel, config_obj: Config, user: LoggedInUser, # pylint: disable=redefined-outer-name html_obj: Optional[htmllib.html] = None, timeout_manager: Optional[TimeoutManager] = None, # pylint: disable=redefined-outer-name theme: Optional[Theme] = None, # pylint: disable=redefined-outer-name display_options: Optional[DisplayOptions] = None, # pylint: disable=redefined-outer-name prefix_logs_with_url: bool = True, endpoint: Optional[Endpoint] = None, # pylint: disable=redefined-outer-name ): self.html = html_obj self.auth_type: Optional[str] = None self.timeout_manager = timeout_manager self.theme = theme self.display_options = display_options self.session: Optional[userdb.Session] = None self.flashes: Optional[List[str]] = None self.translation: Optional[Translation] = None self._prefix_logs_with_url = prefix_logs_with_url self.endpoint = endpoint self.request = req self.response = resp self.output_funnel = funnel self.config = config_obj self._user = user self.user_errors = UserErrors() self._prepend_url_filter = _PrependURLFilter() self._web_log_handler: Optional[logging.Handler] = None
def __init__( self, req: http.Request, resp: http.Response, funnel: OutputFunnel, config_obj: Config, html_obj: Optional[htmllib.html] = None, timeout_manager: Optional[TimeoutManager] = None, # pylint: disable=redefined-outer-name theme: Optional[Theme] = None, # pylint: disable=redefined-outer-name display_options: Optional[DisplayOptions] = None, # pylint: disable=redefined-outer-name prefix_logs_with_url: bool = True, ): self.html = html_obj self.auth_type: Optional[str] = None self.timeout_manager = timeout_manager self.theme = theme self.display_options = display_options self.session: Optional[userdb.Session] = None self.flashes: Optional[List[str]] = None self._prefix_logs_with_url = prefix_logs_with_url self.request = req self.response = resp self.output_funnel = funnel self.config = config_obj # TODO: cyclical import with config -> globals -> config -> ... from cmk.gui.utils.logged_in import LoggedInNobody self._user: LoggedInUser = LoggedInNobody() # TODO: This needs to be a helper of LoggedInUser self.transactions = TransactionManager(req, self._user) self.user_errors = UserErrors() self._prepend_url_filter = _PrependURLFilter() self._web_log_handler: Optional[logging.Handler] = None
def test_user_errors_overwrite() -> None: errors = UserErrors() assert not errors errors.add(MKUserError("varname", "Ding")) assert errors["varname"] == "Ding" errors.add(MKUserError("varname", "Dong")) assert errors["varname"] == "Dong"
def test_user_errors_convert_exception_to_str() -> None: errors = UserErrors() assert not errors errors.add(MKUserError("ding", "Ding")) assert errors["ding"] == "Ding"
def test_user_errors_iter() -> None: errors = UserErrors() errors.add(MKUserError(None, "abc")) errors.add(MKUserError("ding", "aaa")) assert sorted(list(errors.values())) == sorted(["aaa", "abc"])
def test_user_errors_get_not_existing() -> None: assert UserErrors().get("not_existing") is None
def test_user_errors_get() -> None: errors = UserErrors() errors.add(MKUserError("var", "abc")) assert errors["var"] == "abc" assert errors.get("var") == "abc"