Test that a state hydrate event is processed correctly. Args: app_module_mock: The app module that will be returned by get_app(). token: A token. test_state: State to process event. expected: Expected delta. mocker: pytest mock object.
(app_module_mock, token, test_state, expected, mocker)
| 2385 | ], |
| 2386 | ) |
| 2387 | async def test_preprocess(app_module_mock, token, test_state, expected, mocker): |
| 2388 | """Test that a state hydrate event is processed correctly. |
| 2389 | |
| 2390 | Args: |
| 2391 | app_module_mock: The app module that will be returned by get_app(). |
| 2392 | token: A token. |
| 2393 | test_state: State to process event. |
| 2394 | expected: Expected delta. |
| 2395 | mocker: pytest mock object. |
| 2396 | """ |
| 2397 | mocker.patch("nextpy.state.State.class_subclasses", {test_state}) |
| 2398 | app = app_module_mock.app = App( |
| 2399 | state=State, load_events={"index": [test_state.test_handler]} |
| 2400 | ) |
| 2401 | state = State() |
| 2402 | |
| 2403 | updates = [] |
| 2404 | async for update in xt.app.process( |
| 2405 | app=app, |
| 2406 | event=Event( |
| 2407 | token=token, |
| 2408 | name=f"{state.get_name()}.{CompileVars.ON_LOAD_INTERNAL}", |
| 2409 | router_data={RouteVar.PATH: "/", RouteVar.ORIGIN: "/", RouteVar.QUERY: {}}, |
| 2410 | ), |
| 2411 | sid="sid", |
| 2412 | headers={}, |
| 2413 | client_ip="", |
| 2414 | ): |
| 2415 | assert isinstance(update, StateUpdate) |
| 2416 | updates.append(update) |
| 2417 | assert len(updates) == 1 |
| 2418 | assert updates[0].delta["state"].pop("router") is not None |
| 2419 | assert updates[0].delta == exp_is_hydrated(state, False) |
| 2420 | |
| 2421 | events = updates[0].events |
| 2422 | assert len(events) == 2 |
| 2423 | assert (await state._process(events[0]).__anext__()).delta == { |
| 2424 | test_state.get_full_name(): {"num": 1} |
| 2425 | } |
| 2426 | assert (await state._process(events[1]).__anext__()).delta == exp_is_hydrated(state) |
| 2427 | |
| 2428 | |
| 2429 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected