| 290 | |
| 291 | |
| 292 | def 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 | |
| 328 | def test_request_state(test_client_factory: TestClientFactory) -> None: |