Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aecc5e6
rx.State as base state
ElijahAhianyo Nov 8, 2023
18b6447
fix app harness tests
ElijahAhianyo Nov 10, 2023
b27db35
fix app harness(except dynamic routes)
ElijahAhianyo Nov 15, 2023
9205a16
remove debug lines
ElijahAhianyo Nov 15, 2023
7ae9b44
remove debug lines
ElijahAhianyo Nov 15, 2023
2f11980
fix for reflex web
ElijahAhianyo Nov 15, 2023
68a5df8
uncomment dynamic route state
ElijahAhianyo Nov 15, 2023
7bc3c71
remove debug lines
ElijahAhianyo Nov 15, 2023
ba6cfd3
monkeypatch validate_field_name in pydantic
ElijahAhianyo Nov 21, 2023
6464391
partial unit test fix
ElijahAhianyo Nov 21, 2023
90519fb
fix unit tests
ElijahAhianyo Nov 23, 2023
b282f6b
fix upload integration test
ElijahAhianyo Nov 23, 2023
4324f22
fix all unit tests
ElijahAhianyo Nov 24, 2023
e1983ea
fix merge conflicts
ElijahAhianyo Nov 24, 2023
79569ae
fix redis app harness test
ElijahAhianyo Nov 27, 2023
e7a26ab
fix unit tests
ElijahAhianyo Nov 27, 2023
1aee58a
add comments
ElijahAhianyo Nov 27, 2023
b6e465a
remove debug lines
ElijahAhianyo Nov 27, 2023
ca82705
remove dead code
ElijahAhianyo Nov 27, 2023
535c48b
Update reflex/constants/base.py
ElijahAhianyo Nov 28, 2023
7fcc0f2
Update reflex/state.py
ElijahAhianyo Nov 28, 2023
0ba0c8c
fix precommit
ElijahAhianyo Nov 28, 2023
c36a6df
Only track direct subclasses of each BaseState class
masenf Nov 28, 2023
9b75992
Merge pull request #2227 from reflex-dev/masenf/track-subclasses-in-set
ElijahAhianyo Nov 28, 2023
68d8352
state: remove duplicate subclass names when testing
masenf Nov 29, 2023
8798165
Merge branch 'main' into REF-1052/Handle_rx.state_multiple_substates
masenf Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration/test_background_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def index() -> rx.Component:
rx.button("Reset", on_click=State.reset_counter, id="reset"),
)

app = rx.App(state=State)
app = rx.App(state=rx.State)
app.add_page(index)
app.compile()

Expand Down
2 changes: 1 addition & 1 deletion integration/test_call_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def reset_(self):
yield rx.call_script("inline_counter = 0; external_counter = 0")
self.reset()

app = rx.App(state=CallScriptState)
app = rx.App(state=rx.State)
with open("assets/external.js", "w") as f:
f.write(external_scripts)

Expand Down
54 changes: 30 additions & 24 deletions integration/test_client_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def index():
rx.box(ClientSideSubSubState.l1s, id="l1s"),
)

app = rx.App(state=ClientSideState)
app = rx.App(state=rx.State)
app.add_page(index)
app.add_page(index, route="/foo")
app.compile()
Expand Down Expand Up @@ -263,7 +263,6 @@ async def test_client_side_state(
state_var_input.send_keys("c7")
input_value_input.send_keys("c7 value")
set_sub_state_button.click()

state_var_input.send_keys("l1")
input_value_input.send_keys("l1 value")
set_sub_state_button.click()
Expand All @@ -276,7 +275,6 @@ async def test_client_side_state(
state_var_input.send_keys("l4")
input_value_input.send_keys("l4 value")
set_sub_state_button.click()

state_var_input.send_keys("c1s")
input_value_input.send_keys("c1s value")
set_sub_sub_state_button.click()
Expand All @@ -285,28 +283,28 @@ async def test_client_side_state(
set_sub_sub_state_button.click()

exp_cookies = {
"client_side_state.client_side_sub_state.c1": {
"state.client_side_state.client_side_sub_state.c1": {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c1",
"name": "state.client_side_state.client_side_sub_state.c1",
"path": "/",
"sameSite": "Lax",
"secure": False,
"value": "c1%20value",
},
"client_side_state.client_side_sub_state.c2": {
"state.client_side_state.client_side_sub_state.c2": {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c2",
"name": "state.client_side_state.client_side_sub_state.c2",
"path": "/",
"sameSite": "Lax",
"secure": False,
"value": "c2%20value",
},
"client_side_state.client_side_sub_state.c4": {
"state.client_side_state.client_side_sub_state.c4": {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c4",
"name": "state.client_side_state.client_side_sub_state.c4",
"path": "/",
"sameSite": "Strict",
"secure": False,
Expand All @@ -321,19 +319,19 @@ async def test_client_side_state(
"secure": False,
"value": "c6%20value",
},
"client_side_state.client_side_sub_state.c7": {
"state.client_side_state.client_side_sub_state.c7": {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c7",
"name": "state.client_side_state.client_side_sub_state.c7",
"path": "/",
"sameSite": "Lax",
"secure": False,
"value": "c7%20value",
},
"client_side_state.client_side_sub_state.client_side_sub_sub_state.c1s": {
"state.client_side_state.client_side_sub_state.client_side_sub_sub_state.c1s": {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.client_side_sub_sub_state.c1s",
"name": "state.client_side_state.client_side_sub_state.client_side_sub_sub_state.c1s",
"path": "/",
"sameSite": "Lax",
"secure": False,
Expand All @@ -354,40 +352,45 @@ async def test_client_side_state(
input_value_input.send_keys("c3 value")
set_sub_state_button.click()
AppHarness._poll_for(
lambda: "client_side_state.client_side_sub_state.c3" in cookie_info_map(driver)
lambda: "state.client_side_state.client_side_sub_state.c3"
in cookie_info_map(driver)
)
c3_cookie = cookie_info_map(driver)["client_side_state.client_side_sub_state.c3"]
c3_cookie = cookie_info_map(driver)[
"state.client_side_state.client_side_sub_state.c3"
]
assert c3_cookie.pop("expiry") is not None
assert c3_cookie == {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c3",
"name": "state.client_side_state.client_side_sub_state.c3",
"path": "/",
"sameSite": "Lax",
"secure": False,
"value": "c3%20value",
}
time.sleep(2) # wait for c3 to expire
assert "client_side_state.client_side_sub_state.c3" not in cookie_info_map(driver)
assert "state.client_side_state.client_side_sub_state.c3" not in cookie_info_map(
driver
)

local_storage_items = local_storage.items()
local_storage_items.pop("chakra-ui-color-mode", None)
assert (
local_storage_items.pop("client_side_state.client_side_sub_state.l1")
local_storage_items.pop("state.client_side_state.client_side_sub_state.l1")
== "l1 value"
)
assert (
local_storage_items.pop("client_side_state.client_side_sub_state.l2")
local_storage_items.pop("state.client_side_state.client_side_sub_state.l2")
== "l2 value"
)
assert local_storage_items.pop("l3") == "l3 value"
assert (
local_storage_items.pop("client_side_state.client_side_sub_state.l4")
local_storage_items.pop("state.client_side_state.client_side_sub_state.l4")
== "l4 value"
)
assert (
local_storage_items.pop(
"client_side_state.client_side_sub_state.client_side_sub_sub_state.l1s"
"state.client_side_state.client_side_sub_state.client_side_sub_sub_state.l1s"
)
== "l1s value"
)
Expand Down Expand Up @@ -482,12 +485,15 @@ async def test_client_side_state(

# make sure c5 cookie shows up on the `/foo` route
AppHarness._poll_for(
lambda: "client_side_state.client_side_sub_state.c5" in cookie_info_map(driver)
lambda: "state.client_side_state.client_side_sub_state.c5"
in cookie_info_map(driver)
)
assert cookie_info_map(driver)["client_side_state.client_side_sub_state.c5"] == {
assert cookie_info_map(driver)[
"state.client_side_state.client_side_sub_state.c5"
] == {
"domain": "localhost",
"httpOnly": False,
"name": "client_side_state.client_side_sub_state.c5",
"name": "state.client_side_state.client_side_sub_state.c5",
"path": "/foo/",
"sameSite": "Lax",
"secure": False,
Expand Down
2 changes: 1 addition & 1 deletion integration/test_connection_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class State(rx.State):
def index():
return rx.text("Hello World")

app = rx.App(state=State)
app = rx.App(state=rx.State)
app.add_page(index)
app.compile()

Expand Down
8 changes: 5 additions & 3 deletions integration/test_dynamic_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def index():
def redirect_page():
return rx.fragment(rx.text("redirecting..."))

app = rx.App(state=DynamicState)
app = rx.App(state=rx.State)
app.add_page(index)
app.add_page(index, route="/page/[page_id]", on_load=DynamicState.on_load) # type: ignore
app.add_page(index, route="/static/x", on_load=DynamicState.on_load) # type: ignore
Expand Down Expand Up @@ -143,10 +143,12 @@ async def _backend_state():
return await dynamic_route.get_state(token)

async def _check():
return (await _backend_state()).order == exp_order
return (await _backend_state()).substates[
"dynamic_state"
].order == exp_order

await AppHarness._poll_for_async(_check)
assert (await _backend_state()).order == exp_order
assert (await _backend_state()).substates["dynamic_state"].order == exp_order

return _poll_for_order

Expand Down
10 changes: 7 additions & 3 deletions integration/test_event_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def index():
on_click=EventActionState.on_click("outer"), # type: ignore
)

app = rx.App(state=EventActionState)
app = rx.App(state=rx.State)
app.add_page(index)
app.compile()

Expand Down Expand Up @@ -211,10 +211,14 @@ async def _backend_state():
return await event_action.get_state(token)

async def _check():
return (await _backend_state()).order == exp_order
return (await _backend_state()).substates[
"event_action_state"
].order == exp_order

await AppHarness._poll_for_async(_check)
assert (await _backend_state()).order == exp_order
assert (await _backend_state()).substates[
"event_action_state"
].order == exp_order

return _poll_for_order

Expand Down
26 changes: 13 additions & 13 deletions integration/test_event_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def click_yield_interim_value(self):
time.sleep(0.5)
self.interim_value = "final"

app = rx.App(state=State)
app = rx.App(state=rx.State)

token_input = rx.input(
value=State.router.session.client_token, is_read_only=True, id="token"
Expand Down Expand Up @@ -401,12 +401,12 @@ async def test_event_chain_click(
btn.click()

async def _has_all_events():
return len((await event_chain.get_state(token)).event_order) == len(
exp_event_order
)
return len(
(await event_chain.get_state(token)).substates["state"].event_order
) == len(exp_event_order)

await AppHarness._poll_for_async(_has_all_events)
event_order = (await event_chain.get_state(token)).event_order
event_order = (await event_chain.get_state(token)).substates["state"].event_order
assert event_order == exp_event_order


Expand Down Expand Up @@ -453,12 +453,12 @@ async def test_event_chain_on_load(
token = assert_token(event_chain, driver)

async def _has_all_events():
return len((await event_chain.get_state(token)).event_order) == len(
exp_event_order
)
return len(
(await event_chain.get_state(token)).substates["state"].event_order
) == len(exp_event_order)

await AppHarness._poll_for_async(_has_all_events)
backend_state = await event_chain.get_state(token)
backend_state = (await event_chain.get_state(token)).substates["state"]
assert backend_state.event_order == exp_event_order
assert backend_state.is_hydrated is True

Expand Down Expand Up @@ -529,12 +529,12 @@ async def test_event_chain_on_mount(
unmount_button.click()

async def _has_all_events():
return len((await event_chain.get_state(token)).event_order) == len(
exp_event_order
)
return len(
(await event_chain.get_state(token)).substates["state"].event_order
) == len(exp_event_order)

await AppHarness._poll_for_async(_has_all_events)
event_order = (await event_chain.get_state(token)).event_order
event_order = (await event_chain.get_state(token)).substates["state"].event_order
assert event_order == exp_event_order


Expand Down
6 changes: 3 additions & 3 deletions integration/test_form_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FormState(rx.State):
def form_submit(self, form_data: dict):
self.form_data = form_data

app = rx.App(state=FormState)
app = rx.App(state=rx.State)

@app.add_page
def index():
Expand Down Expand Up @@ -75,7 +75,7 @@ class FormState(rx.State):
def form_submit(self, form_data: dict):
self.form_data = form_data

app = rx.App(state=FormState)
app = rx.App(state=rx.State)

@app.add_page
def index():
Expand Down Expand Up @@ -210,7 +210,7 @@ async def test_submit(driver, form_submit: AppHarness):
submit_input.click()

async def get_form_data():
return (await form_submit.get_state(token)).form_data
return (await form_submit.get_state(token)).substates["form_state"].form_data

# wait for the form data to arrive at the backend
form_data = await AppHarness._poll_for_async(get_form_data)
Expand Down
20 changes: 12 additions & 8 deletions integration/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def FullyControlledInput():
class State(rx.State):
text: str = "initial"

app = rx.App(state=State)
app = rx.App(state=rx.State)

@app.add_page
def index():
Expand Down Expand Up @@ -85,13 +85,15 @@ async def test_fully_controlled_input(fully_controlled_input: AppHarness):
debounce_input.send_keys("foo")
time.sleep(0.5)
assert debounce_input.get_attribute("value") == "ifoonitial"
assert (await fully_controlled_input.get_state(token)).text == "ifoonitial"
assert (await fully_controlled_input.get_state(token)).substates[
"state"
].text == "ifoonitial"
assert fully_controlled_input.poll_for_value(value_input) == "ifoonitial"

# clear the input on the backend
async with fully_controlled_input.modify_state(token) as state:
state.text = ""
assert (await fully_controlled_input.get_state(token)).text == ""
state.substates["state"].text = ""
assert (await fully_controlled_input.get_state(token)).substates["state"].text == ""
assert (
fully_controlled_input.poll_for_value(
debounce_input, exp_not_equal="ifoonitial"
Expand All @@ -103,17 +105,19 @@ async def test_fully_controlled_input(fully_controlled_input: AppHarness):
debounce_input.send_keys("getting testing done")
time.sleep(0.5)
assert debounce_input.get_attribute("value") == "getting testing done"
assert (
await fully_controlled_input.get_state(token)
).text == "getting testing done"
assert (await fully_controlled_input.get_state(token)).substates[
"state"
].text == "getting testing done"
assert fully_controlled_input.poll_for_value(value_input) == "getting testing done"

# type into the on_change input
on_change_input.send_keys("overwrite the state")
time.sleep(0.5)
assert debounce_input.get_attribute("value") == "overwrite the state"
assert on_change_input.get_attribute("value") == "overwrite the state"
assert (await fully_controlled_input.get_state(token)).text == "overwrite the state"
assert (await fully_controlled_input.get_state(token)).substates[
"state"
].text == "overwrite the state"
assert fully_controlled_input.poll_for_value(value_input) == "overwrite the state"

clear_button.click()
Expand Down
4 changes: 2 additions & 2 deletions integration/test_login_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def login():
rx.button("Do it", on_click=State.login, id="doit"),
)

app = rx.App(state=State)
app = rx.App(state=rx.State)
app.add_page(index)
app.add_page(login)
app.compile()
Expand Down Expand Up @@ -137,6 +137,6 @@ def check_auth_token_header():
logout_button = driver.find_element(By.ID, "logout")
logout_button.click()

assert login_sample._poll_for(lambda: local_storage["state.auth_token"] == "")
assert login_sample._poll_for(lambda: local_storage["state.state.auth_token"] == "")
with pytest.raises(NoSuchElementException):
driver.find_element(By.ID, "auth-token")
2 changes: 1 addition & 1 deletion integration/test_radix_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def index() -> rx.Component:
)

app = rx.App(
state=State,
state=rx.State,
theme=rdxt.theme(rdxt.theme_panel(), accent_color="grass"),
)
app.add_page(index)
Expand Down
Loading