Home / Function/ test_session_dynamic_cookie_name() — flask Function Reference

test_session_dynamic_cookie_name() — flask Function Reference

Architecture documentation for the test_session_dynamic_cookie_name() function in test_reqctx.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  c81c51c2_aca6_9af5_7238_80915c327d26["test_session_dynamic_cookie_name()"]
  aea65cbf_db83_bd4f_d83f_1a35ae104254["test_reqctx.py"]
  c81c51c2_aca6_9af5_7238_80915c327d26 -->|defined in| aea65cbf_db83_bd4f_d83f_1a35ae104254
  c232e1d3_f26b_5887_467b_a0cb9123960e["get_cookie_name()"]
  c81c51c2_aca6_9af5_7238_80915c327d26 -->|calls| c232e1d3_f26b_5887_467b_a0cb9123960e
  style c81c51c2_aca6_9af5_7238_80915c327d26 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_reqctx.py lines 229–277

def test_session_dynamic_cookie_name():
    # This session interface will use a cookie with a different name if the
    # requested url ends with the string "dynamic_cookie"
    class PathAwareSessionInterface(SecureCookieSessionInterface):
        def get_cookie_name(self, app):
            if flask.request.url.endswith("dynamic_cookie"):
                return "dynamic_cookie_name"
            else:
                return super().get_cookie_name(app)

    class CustomFlask(flask.Flask):
        session_interface = PathAwareSessionInterface()

    app = CustomFlask(__name__)
    app.secret_key = "secret_key"

    @app.route("/set", methods=["POST"])
    def set():
        flask.session["value"] = flask.request.form["value"]
        return "value set"

    @app.route("/get")
    def get():
        v = flask.session.get("value", "None")
        return v

    @app.route("/set_dynamic_cookie", methods=["POST"])
    def set_dynamic_cookie():
        flask.session["value"] = flask.request.form["value"]
        return "value set"

    @app.route("/get_dynamic_cookie")
    def get_dynamic_cookie():
        v = flask.session.get("value", "None")
        return v

    test_client = app.test_client()

    # first set the cookie in both /set urls but each with a different value
    assert test_client.post("/set", data={"value": "42"}).data == b"value set"
    assert (
        test_client.post("/set_dynamic_cookie", data={"value": "616"}).data
        == b"value set"
    )

    # now check that the relevant values come back - meaning that different
    # cookies are being used for the urls that end with "dynamic cookie"
    assert test_client.get("/get").data == b"42"
    assert test_client.get("/get_dynamic_cookie").data == b"616"

Subdomains

Frequently Asked Questions

What does test_session_dynamic_cookie_name() do?
test_session_dynamic_cookie_name() is a function in the flask codebase, defined in tests/test_reqctx.py.
Where is test_session_dynamic_cookie_name() defined?
test_session_dynamic_cookie_name() is defined in tests/test_reqctx.py at line 229.
What does test_session_dynamic_cookie_name() call?
test_session_dynamic_cookie_name() calls 1 function(s): get_cookie_name.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free