MCPcopy
hub / github.com/encode/starlette / test_session_tracks_modification

Function test_session_tracks_modification

tests/middleware/test_session.py:251–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

249
250
251def test_session_tracks_modification() -> None:
252 session = Session({"a": "1", "b": "2"})
253 assert not session.modified
254
255 # __setitem__
256 session["c"] = "3"
257 assert session.modified
258
259 # __delitem__
260 session = Session({"a": "1"})
261 del session["a"]
262 assert session.modified
263
264 # clear
265 session = Session({"a": "1"})
266 session.clear()
267 assert session.modified
268
269 # pop with existing key
270 session = Session({"a": "1"})
271 session.pop("a")
272 assert session.modified
273
274 # pop with missing key
275 session = Session({"a": "1"})
276 session.pop("missing", None)
277 assert not session.modified
278
279 # setdefault with missing key
280 session = Session({"a": "1"})
281 session.setdefault("b", "2")
282 assert session.modified
283
284 # setdefault with existing key
285 session = Session({"a": "1"})
286 session.setdefault("a", "2")
287 assert not session.modified

Callers

nothing calls this directly

Calls 4

clearMethod · 0.95
popMethod · 0.95
setdefaultMethod · 0.95
SessionClass · 0.90

Tested by

no test coverage detected