MCPcopy
hub / github.com/pallets/flask / test_session_accessed

Function test_session_accessed

tests/test_basic.py:236–275  ·  view source on GitHub ↗
(app: flask.Flask, client: FlaskClient)

Source from the content-addressed store, hash-verified

234
235
236def test_session_accessed(app: flask.Flask, client: FlaskClient) -> None:
237 @app.post("/")
238 def do_set():
239 flask.session["value"] = flask.request.form["value"]
240 return "value set"
241
242 @app.get("/")
243 def do_get():
244 return flask.session.get("value", "None")
245
246 @app.get("/nothing")
247 def do_nothing() -> str:
248 return ""
249
250 with client:
251 rv = client.get("/nothing")
252 assert "cookie" not in rv.vary
253 assert not request_ctx._session.accessed
254 assert not request_ctx._session.modified
255
256 with client:
257 rv = client.post(data={"value": "42"})
258 assert rv.text == "value set"
259 assert "cookie" in rv.vary
260 assert request_ctx._session.accessed
261 assert request_ctx._session.modified
262
263 with client:
264 rv = client.get()
265 assert rv.text == "42"
266 assert "cookie" in rv.vary
267 assert request_ctx._session.accessed
268 assert not request_ctx._session.modified
269
270 with client:
271 rv = client.get("/nothing")
272 assert rv.text == ""
273 assert "cookie" not in rv.vary
274 assert not request_ctx._session.accessed
275 assert not request_ctx._session.modified
276
277
278def test_session_path(app, client):

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected