(app)
| 470 | |
| 471 | |
| 472 | def 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 | |
| 513 | def test_session_vary_cookie(app, client): |
nothing calls this directly
no test coverage detected