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

Function test_session_vary_cookie

tests/test_basic.py:513–571  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

511
512
513def test_session_vary_cookie(app, client):
514 @app.route("/set")
515 def set_session():
516 flask.session["test"] = "test"
517 return ""
518
519 @app.route("/get")
520 def get():
521 return flask.session.get("test")
522
523 @app.route("/getitem")
524 def getitem():
525 return flask.session["test"]
526
527 @app.route("/setdefault")
528 def setdefault():
529 return flask.session.setdefault("test", "default")
530
531 @app.route("/clear")
532 def clear():
533 flask.session.clear()
534 return ""
535
536 @app.route("/vary-cookie-header-set")
537 def vary_cookie_header_set():
538 response = flask.Response()
539 response.vary.add("Cookie")
540 flask.session["test"] = "test"
541 return response
542
543 @app.route("/vary-header-set")
544 def vary_header_set():
545 response = flask.Response()
546 response.vary.update(("Accept-Encoding", "Accept-Language"))
547 flask.session["test"] = "test"
548 return response
549
550 @app.route("/no-vary-header")
551 def no_vary_header():
552 return ""
553
554 def expect(path, header_value="Cookie"):
555 rv = client.get(path)
556
557 if header_value:
558 # The 'Vary' key should exist in the headers only once.
559 assert len(rv.headers.get_all("Vary")) == 1
560 assert rv.headers["Vary"] == header_value
561 else:
562 assert "Vary" not in rv.headers
563
564 expect("/set")
565 expect("/get")
566 expect("/getitem")
567 expect("/setdefault")
568 expect("/clear")
569 expect("/vary-cookie-header-set")
570 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")

Callers

nothing calls this directly

Calls 1

expectFunction · 0.85

Tested by

no test coverage detected