Test that an event is processed properly and that it is postprocessed n+1 times. Also check that the processing flag of the last stateupdate is set to False. Args: mocker: mocker object. token: a Token.
(mocker, token: str)
| 1108 | |
| 1109 | @pytest.mark.asyncio |
| 1110 | async def test_process_events(mocker, token: str): |
| 1111 | """Test that an event is processed properly and that it is postprocessed |
| 1112 | n+1 times. Also check that the processing flag of the last stateupdate is set to |
| 1113 | False. |
| 1114 | |
| 1115 | Args: |
| 1116 | mocker: mocker object. |
| 1117 | token: a Token. |
| 1118 | """ |
| 1119 | router_data = { |
| 1120 | "pathname": "/", |
| 1121 | "query": {}, |
| 1122 | "token": token, |
| 1123 | "sid": "mock_sid", |
| 1124 | "headers": {}, |
| 1125 | "ip": "127.0.0.1", |
| 1126 | } |
| 1127 | app = App(state=GenState) |
| 1128 | mocker.patch.object(app, "postprocess", AsyncMock()) |
| 1129 | event = Event( |
| 1130 | token=token, name="gen_state.go", payload={"c": 5}, router_data=router_data |
| 1131 | ) |
| 1132 | |
| 1133 | async for _update in process(app, event, "mock_sid", {}, "127.0.0.1"): |
| 1134 | pass |
| 1135 | |
| 1136 | assert (await app.state_manager.get_state(token)).value == 5 |
| 1137 | assert app.postprocess.call_count == 6 |
| 1138 | |
| 1139 | if isinstance(app.state_manager, StateManagerRedis): |
| 1140 | await app.state_manager.close() |
| 1141 | |
| 1142 | |
| 1143 | @pytest.mark.parametrize( |