MCPcopy Create free account
hub / github.com/pallets/flask / test_session_cookie_setting

Function test_session_cookie_setting

tests/test_basic.py:472–510  ·  view source on GitHub ↗
(app)

Source from the content-addressed store, hash-verified

470
471
472def test_session_cookie_setting(app):
473 is_permanent = True
474
475 @app.route("/bump")
476 def bump():
477 rv = flask.session["foo"] = flask.session.get("foo", 0) + 1
478 flask.session.permanent = is_permanent
479 return str(rv)
480
481 @app.route("/read")
482 def read():
483 return str(flask.session.get("foo", 0))
484
485 def run_test(expect_header):
486 with app.test_client() as c:
487 assert c.get("/bump").data == b"1"
488 assert c.get("/bump").data == b"2"
489 assert c.get("/bump").data == b"3"
490
491 rv = c.get("/read")
492 set_cookie = rv.headers.get("set-cookie")
493 assert (set_cookie is not None) == expect_header
494 assert rv.data == b"3"
495
496 is_permanent = True
497 app.config["SESSION_REFRESH_EACH_REQUEST"] = True
498 run_test(expect_header=True)
499
500 is_permanent = True
501 app.config["SESSION_REFRESH_EACH_REQUEST"] = False
502 run_test(expect_header=False)
503
504 is_permanent = False
505 app.config["SESSION_REFRESH_EACH_REQUEST"] = True
506 run_test(expect_header=False)
507
508 is_permanent = False
509 app.config["SESSION_REFRESH_EACH_REQUEST"] = False
510 run_test(expect_header=False)
511
512
513def test_session_vary_cookie(app, client):

Callers

nothing calls this directly

Calls 1

run_testFunction · 0.85

Tested by

no test coverage detected