
* rename private fields with leading underscore in App
* fix constants API
* fix public API for some attributes of App()
* fix conflicts properly 🙈
* remove extra private
---------
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: Khaleel Al-Adhami <khaleel.aladhami@gmail.com>
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from reflex.app import App
|
|
from reflex.middleware.hydrate_middleware import HydrateMiddleware
|
|
from reflex.state import State, StateUpdate
|
|
|
|
|
|
class TestState(State):
|
|
"""A test state with no return in handler."""
|
|
|
|
__test__ = False
|
|
|
|
num: int = 0
|
|
|
|
def test_handler(self):
|
|
"""Test handler."""
|
|
self.num += 1
|
|
|
|
|
|
@pytest.fixture
|
|
def hydrate_middleware() -> HydrateMiddleware:
|
|
"""Fixture creates an instance of HydrateMiddleware per test case.
|
|
|
|
Returns:
|
|
instance of HydrateMiddleware
|
|
"""
|
|
return HydrateMiddleware()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_preprocess_no_events(hydrate_middleware, event1, mocker):
|
|
"""Test that app without on_load is processed correctly.
|
|
|
|
Args:
|
|
hydrate_middleware: Instance of HydrateMiddleware
|
|
event1: An Event.
|
|
mocker: pytest mock object.
|
|
"""
|
|
mocker.patch("reflex.state.State.class_subclasses", {TestState})
|
|
state = State()
|
|
update = await hydrate_middleware.preprocess(
|
|
app=App(_state=State),
|
|
event=event1,
|
|
state=state,
|
|
)
|
|
assert isinstance(update, StateUpdate)
|
|
assert update.delta == state.dict()
|
|
assert not update.events
|