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

Function test_request_state_object

tests/test_requests.py:292–325  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

290
291
292def test_request_state_object() -> None:
293 scope = {"state": {"old": "foo"}}
294
295 s = State(scope["state"])
296
297 s.new = "value"
298 assert s.new == "value"
299
300 del s.new
301
302 with pytest.raises(AttributeError):
303 s.new
304
305 # Test dictionary-style methods
306 # Test __setitem__
307 s["dict_key"] = "dict_value"
308 assert s["dict_key"] == "dict_value"
309 assert s.dict_key == "dict_value"
310
311 # Test __iter__
312 s["another_key"] = "another_value"
313 keys = list(s)
314 assert "old" in keys
315 assert "dict_key" in keys
316 assert "another_key" in keys
317
318 # Test __len__
319 assert len(s) == 3
320
321 # Test __delitem__
322 del s["dict_key"]
323 assert len(s) == 2
324 with pytest.raises(KeyError):
325 s["dict_key"]
326
327
328def test_request_state(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 1

StateClass · 0.90

Tested by

no test coverage detected