Example #1
0
def _incognito(response: flask.wrappers.Response) -> flask.wrappers.Response:
    """Replace all numbers with 'X'."""
    if app.config.get("INCOGNITO") and response.content_type.startswith(
            "text/html"):
        is_editor = (request.endpoint == "report"
                     and request.view_args is not None
                     and request.view_args["report_name"] == "editor")
        if not is_editor:
            original_text = response.get_data(as_text=True)
            response.set_data(replace_numbers(original_text))
    return response
Example #2
0
def assert_equals(response: fl.wrappers.Response, status_code: int) -> dict:
    """Base function that check response status
    Equals to passed status_code and response has a message field

    Args:
        response (): .
        status_code (int): .

    Return:
        response dictionary

    Raises:
        AssertionError: If status_code doesn't match or response has no
        message field

    """

    json_response = response.get_json()

    assert response.status_code == status_code
    assert "message" in json_response.keys()
    assert "status_code" in json_response.keys()
    assert json_response["status_code"] == status_code

    return json_response
 def _set_cookie_token_in_response(
     response: flask.wrappers.Response, ) -> flask.wrappers.Response:
     if "set_cookie_token" in flask.g and flask.g.set_cookie_token:
         response.set_cookie(key=f"cookie_token_{self._port}",
                             value=self._cookie_token)
     return response
Example #4
0
 def after_request(
     response: flask.wrappers.Response, ) -> flask.wrappers.Response:
     for header, value in headers:
         response.headers[header] = value
     return response
Example #5
0
 def _set_cookie_token_in_response(
     response: flask.wrappers.Response, ) -> flask.wrappers.Response:
     if flask.g.get("set_cookie_token", False):
         response.set_cookie(key=f"cookie_token_{self._port}",
                             value=self._cookie_token)
     return response