@@ -1948,17 +1948,25 @@ class ModelDC:
19481948
19491949
19501950@pytest .mark .asyncio
1951- async def test_state_proxy (grandchild_state : GrandchildState , mock_app : rx .App ):
1951+ async def test_state_proxy (
1952+ grandchild_state : GrandchildState , mock_app : rx .App , token : str
1953+ ):
19521954 """Test that the state proxy works.
19531955
19541956 Args:
19551957 grandchild_state: A grandchild state.
19561958 mock_app: An app that will be returned by `get_app()`
1959+ token: A token.
19571960 """
19581961 child_state = grandchild_state .parent_state
19591962 assert child_state is not None
19601963 parent_state = child_state .parent_state
19611964 assert parent_state is not None
1965+ router_data = RouterData ({"query" : {}, "token" : token , "sid" : "test_sid" })
1966+ grandchild_state .router = router_data
1967+ namespace = mock_app .event_namespace
1968+ assert namespace is not None
1969+ namespace .sid_to_token [router_data .session .session_id ] = token
19621970 if isinstance (mock_app .state_manager , (StateManagerMemory , StateManagerDisk )):
19631971 mock_app .state_manager .states [parent_state .router .session .client_token ] = (
19641972 parent_state
@@ -2029,6 +2037,7 @@ async def test_state_proxy(grandchild_state: GrandchildState, mock_app: rx.App):
20292037 assert mcall .args [0 ] == str (SocketEvent .EVENT )
20302038 assert mcall .args [1 ] == StateUpdate (
20312039 delta = {
2040+ TestState .get_full_name (): {"router" : router_data },
20322041 grandchild_state .get_full_name (): {
20332042 "value2" : "42" ,
20342043 },
@@ -2154,7 +2163,11 @@ async def test_background_task_no_block(mock_app: rx.App, token: str):
21542163 mock_app: An app that will be returned by `get_app()`
21552164 token: A token.
21562165 """
2157- router_data = {"query" : {}}
2166+ router_data = {"query" : {}, "token" : token }
2167+ sid = "test_sid"
2168+ namespace = mock_app .event_namespace
2169+ assert namespace is not None
2170+ namespace .sid_to_token [sid ] = token
21582171 mock_app .state_manager .state = mock_app ._state = BackgroundTaskState
21592172 async for update in rx .app .process (
21602173 mock_app ,
@@ -2164,7 +2177,7 @@ async def test_background_task_no_block(mock_app: rx.App, token: str):
21642177 router_data = router_data ,
21652178 payload = {},
21662179 ),
2167- sid = "" ,
2180+ sid = sid ,
21682181 headers = {},
21692182 client_ip = "" ,
21702183 ):
@@ -2184,7 +2197,7 @@ async def test_background_task_no_block(mock_app: rx.App, token: str):
21842197 router_data = router_data ,
21852198 payload = {},
21862199 ),
2187- sid = "" ,
2200+ sid = sid ,
21882201 headers = {},
21892202 client_ip = "" ,
21902203 ):
0 commit comments