From e15710de17517a06c15cc6ea6cc001f8851fbf19 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 18 Oct 2023 03:29:24 -0700 Subject: [PATCH] test_app: cleanup state_name logic and fixup get_sid() call (#1993) --- tests/test_app.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index 51181ddf4..5ea59e1e0 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -736,6 +736,7 @@ async def test_upload_file(tmp_path, state, delta, token: str): token: a Token. """ state._tmp_path = tmp_path + # The App state must be the "root" of the state tree app = App(state=state if state is FileUploadState else FileStateBase1) app.event_namespace.emit = AsyncMock() # type: ignore current_state = await app.state_manager.get_state(token) @@ -745,10 +746,8 @@ async def test_upload_file(tmp_path, state, delta, token: str): bio = io.BytesIO() bio.write(data) - if state is FileUploadState: - handler_prefix = f"{token}:{state.get_name()}" - else: - handler_prefix = f"{token}:{state.get_full_name().partition('.')[2]}" + state_name = state.get_full_name().partition(".")[2] or state.get_name() + handler_prefix = f"{token}:{state_name}" file1 = UploadFile( filename=f"{handler_prefix}.multi_handle_upload:True:image1.jpg", @@ -763,7 +762,7 @@ async def test_upload_file(tmp_path, state, delta, token: str): state_update = StateUpdate(delta=delta, events=[], final=True) app.event_namespace.emit.assert_called_with( # type: ignore - "event", state_update.json(), to=current_state.get_sid() + "event", state_update.json(), to=current_state.router.session.session_id ) current_state = await app.state_manager.get_state(token) state_dict = current_state.dict() @@ -798,12 +797,10 @@ async def test_upload_file_without_annotation(state, tmp_path, token): bio.write(data) state._tmp_path = tmp_path + # The App state must be the "root" of the state tree app = App(state=state if state is FileUploadState else FileStateBase1) - if state is FileUploadState: - state_name = state.get_name() - else: - state_name = state.get_full_name().partition(".")[2] + state_name = state.get_full_name().partition(".")[2] or state.get_name() handler_prefix = f"{token}:{state_name}" file1 = UploadFile(