Skip to content

Commit

Permalink
per Fabien + test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Sep 15, 2024
1 parent 9fc64b1 commit 218881d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion taipy/gui/custom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from ._page import ResourceHandler, _ExternalResourceHandlerManager


def is_in_custom_page_context():
def is_in_custom_page_context() -> bool:
"NOT DOCUMENTED"
resource_handler_id = None
with contextlib.suppress(Exception):
if has_request_context():
Expand All @@ -28,6 +29,7 @@ def is_in_custom_page_context():


def get_current_resource_handler() -> t.Optional[ResourceHandler]:
"NOT DOCUMENTED"
resource_handler_id = None
with contextlib.suppress(Exception):
if has_request_context():
Expand Down
12 changes: 8 additions & 4 deletions tests/gui/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ def assert_outward_ws_message(received_message, type, varname, value):
args = received_message["args"]
assert "type" in args and args["type"] == type
assert "payload" in args
payload = args["payload"][0]
assert "name" in payload and varname in payload["name"]
assert "payload" in payload and "value" in payload["payload"] and payload["payload"]["value"] == value
logging.getLogger().debug(payload["payload"]["value"])
payload_arr = args["payload"]
found_payload = False
for payload in payload_arr:
if "name" in payload and varname in payload["name"]:
assert "payload" in payload and "value" in payload["payload"] and payload["payload"]["value"] == value
found_payload = True
logging.getLogger().debug(payload["payload"]["value"])
assert found_payload

@staticmethod
def assert_outward_simple_ws_message(received_message, type, varname, value):
Expand Down
4 changes: 2 additions & 2 deletions tests/gui/server/ws/test_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def do_something(state, id):
assert gui._bindings()._get_all_scopes()[sid].x == 20 # type: ignore
# assert for received message (message that would be sent to the front-end client)
received_messages = ws_client.get_received()
helpers.assert_outward_ws_message(received_messages[0], "MU", "x", 20)
helpers.assert_outward_ws_message(received_messages[1], "MU", "text", "a random text")
helpers.assert_outward_ws_message(received_messages[0], "MU", "tpec_TpExPr_x_TPMDL_0", 20)
helpers.assert_outward_ws_message(received_messages[1], "MU", "tpec_TpExPr_text_TPMDL_0", "a random text")
9 changes: 7 additions & 2 deletions tests/gui/server/ws/test_ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ def test_ru_selector(gui: Gui, helpers, csvdata):
sid = helpers.create_scope_and_get_sid(gui)
# Get the jsx once so that the page will be evaluated -> variable will be registered
flask_client.get(f"/taipy-jsx/test?client_id={sid}")
ws_client.emit("message", {"client_id": sid, "type": "RU", "name": "", "payload": {"names": ["selected_val"]}})
ws_client.emit(
"message",
{"client_id": sid, "type": "RU", "name": "", "payload": {"names": ["_TpLv_tpec_TpExPr_selected_val_TPMDL_0"]}},
)
# assert for received message (message that would be sent to the front-end client)
received_messages = ws_client.get_received()
assert len(received_messages)
helpers.assert_outward_ws_message(received_messages[0], "MU", "selected_val", ["value1", "value2"])
helpers.assert_outward_ws_message(
received_messages[0], "MU", "_TpLv_tpec_TpExPr_selected_val_TPMDL_0", ["value1", "value2"]
)

0 comments on commit 218881d

Please sign in to comment.