Exemple #1
0
    def __call__(self, environ, start_response):
        req = http.Request(environ)

        output_format = get_output_format(
            req.get_ascii_input_mandatory("output_format", "html").lower())
        mime_type = get_mime_type_from_output_format(output_format)

        resp = Response(headers=default_response_headers(req),
                        mimetype=mime_type)
        funnel = OutputFunnel(resp)

        timeout_manager = TimeoutManager()
        timeout_manager.enable_timeout(req.request_timeout)

        theme = Theme()

        with AppContext(self), RequestContext(
                req=req,
                resp=resp,
                funnel=funnel,
                html_obj=htmllib.html(req, resp, funnel, output_format),
                timeout_manager=timeout_manager,
                display_options=DisplayOptions(),
                theme=theme,
        ), patch_json(json):
            config.initialize()
            theme.from_config(config.ui_theme, config.theme_choices())
            return self.wsgi_app(environ, start_response)
Exemple #2
0
    def __call__(self, environ: WSGIEnvironment,
                 start_response: StartResponse) -> WSGIResponse:
        req = http.Request(environ)

        output_format = get_output_format(
            req.get_ascii_input_mandatory("output_format", "html").lower())
        mime_type = get_mime_type_from_output_format(output_format)

        resp = Response(headers=default_response_headers(req),
                        mimetype=mime_type)
        funnel = OutputFunnel(resp)

        timeout_manager = TimeoutManager()
        timeout_manager.enable_timeout(req.request_timeout)

        theme = Theme()
        config_obj = config_module.make_config_object(
            config_module.get_default_config())

        with AppContext(self), RequestContext(
                req=req,
                resp=resp,
                funnel=funnel,
                config_obj=config_obj,
                user=LoggedInNobody(),
                html_obj=htmllib.html(req, resp, funnel, output_format),
                timeout_manager=timeout_manager,
                display_options=DisplayOptions(),
                theme=theme,
        ), patch_json(json):
            config_module.initialize()
            theme.from_config(config.ui_theme)
            return self.wsgi_app(environ, start_response)
Exemple #3
0
def test_has_custom_logo(monkeypatch, th: Theme, edition_short: str,
                         with_logo: bool) -> None:
    monkeypatch.setattr("cmk.utils.version.edition_short",
                        lambda: edition_short)
    if with_logo:
        th.base_dir().joinpath("images").mkdir(parents=True, exist_ok=True)
        th.base_dir().joinpath("images", "mk-logo.png").touch()
    assert th.has_custom_logo() is (edition_short == "cme" and with_logo)
Exemple #4
0
def test_has_custom_logo(monkeypatch, th: Theme,
                         edition: cmk.utils.version.Edition,
                         with_logo: bool) -> None:
    monkeypatch.setattr("cmk.gui.utils.theme.is_managed_edition",
                        lambda: edition is cmk.utils.version.Edition.CME)
    if with_logo:
        th.base_dir().joinpath("images").mkdir(parents=True, exist_ok=True)
        th.base_dir().joinpath("images", "mk-logo.png").touch()
    assert th.has_custom_logo() is (edition is cmk.utils.version.Edition.CME
                                    and with_logo)
Exemple #5
0
def test_detect_icon_path(th: Theme) -> None:
    assert th.get() == "modern-dark"
    assert th.detect_icon_path(
        "xyz", prefix="icon_") == "themes/facelift/images/icon_missing.svg"
    assert th.detect_icon_path(
        "ldap", prefix="icon_") == "themes/facelift/images/icon_ldap.svg"
    assert th.detect_icon_path(
        "email", prefix="icon_") == "themes/facelift/images/icon_email.png"
    assert th.detect_icon_path(
        "window_list", prefix="icon_") == "images/icons/window_list.png"
Exemple #6
0
 def _SearchContext(self) -> Iterator[None]:
     _request = Request(create_environ())
     _response = Response()
     _funnel = OutputFunnel(_response)
     _theme = Theme()
     _theme.from_config(config.ui_theme, config.theme_choices())
     with RequestContext(
             req=_request,
             resp=_response,
             funnel=_funnel,
             html_obj=html(_request,
                           _response,
                           _funnel,
                           output_format="html"),
             display_options=DisplayOptions(),
             theme=_theme,
     ), UserContext(self._user_id):
         yield
Exemple #7
0
def request_context(environ: Mapping[str, Any]) -> Iterator[None]:
    req = Request(environ)
    resp = Response(mimetype="text/html")
    funnel = OutputFunnel(resp)
    with RequestContext(
            req=req,
            resp=resp,
            funnel=funnel,
            html_obj=html(req, resp, funnel, output_format="html"),
            display_options=DisplayOptions(),
            theme=Theme(),
            prefix_logs_with_url=False,
    ):
        yield
Exemple #8
0
def make_request_context(
        environ: Optional[Mapping[str, Any]] = None) -> RequestContext:
    req = Request(
        dict(create_environ(), REQUEST_URI="") if environ is None else environ)
    resp = Response(mimetype="text/html")
    funnel = OutputFunnel(resp)
    return RequestContext(
        req=req,
        resp=resp,
        funnel=funnel,
        config_obj=make_config_object(get_default_config()),
        user=LoggedInNobody(),
        html_obj=html(req, resp, funnel, output_format="html"),
        display_options=DisplayOptions(),
        timeout_manager=TimeoutManager(),
        theme=Theme(),
        prefix_logs_with_url=False,
    )
Exemple #9
0
def test_base_dir(th: Theme) -> None:
    assert th.base_dir(
    ) == cmk.utils.paths.local_web_dir / "htdocs" / "themes" / "modern-dark"
Exemple #10
0
def test_url(th: Theme) -> None:
    assert th.url("asd/eee") == "themes/modern-dark/asd/eee"
Exemple #11
0
def test_icon_themes(th: Theme) -> None:
    assert th.icon_themes() == ["modern-dark", "facelift"]

    th.set("facelift")
    assert th.get() == "facelift"
    assert th.icon_themes() == ["facelift"]
Exemple #12
0
def fixture_th() -> Theme:
    th = Theme()
    th.from_config("modern-dark")
    assert th.get() == "modern-dark"
    return th
Exemple #13
0
def fixture_th() -> Theme:
    th = Theme()
    th.from_config("modern-dark", config.theme_choices())
    assert th.get() == "modern-dark"
    return th