From ca96f41a45707bae94525439b2bfa8c9a1eec873 Mon Sep 17 00:00:00 2001 From: x12sa Date: Tue, 13 Oct 2026 10:22:15 +0200 Subject: [PATCH] fix(webpage): name the setup's own client in the web password hint The "no web authentication yet" hint always said flomni.set_web_password(), which doesn't exist in a LamNI session. Each generator now declares CLIENT_NAME and the hint uses it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ALDnH16dC6iyHjhe5Ey4w9 --- .../plugins/LamNI/LamNI_webpage_generator.py | 2 ++ .../OMNY_shared/webpage_generator_base.py | 9 +++-- .../flomni/flomni_webpage_generator.py | 2 ++ .../test_webpage_password_hint.py | 35 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/tests_bec_ipython_client/test_webpage_password_hint.py diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/LamNI_webpage_generator.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/LamNI_webpage_generator.py index f64dc4df..5ad2ac99 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/LamNI_webpage_generator.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/LamNI_webpage_generator.py @@ -46,6 +46,8 @@ class LamniWebpageGenerator(WebpageGeneratorBase): sample name, and measurement settings. """ + CLIENT_NAME = "lamni" + # LamNI's tomo-queue jobs (added via TomoQueueMixin, see # OMNY_shared/tomo_queue_mixin.py) are persisted under the same # "tomo_queue" global var key flomni uses, so the shared "Tomo queue" diff --git a/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/webpage_generator_base.py b/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/webpage_generator_base.py index 38028410..8b0dbf25 100644 --- a/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/webpage_generator_base.py +++ b/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/webpage_generator_base.py @@ -443,6 +443,10 @@ class WebpageGeneratorBase: whole shared output dir, EPS files included. """ + # Name of the setup's object in the BEC client namespace (e.g. "lamni"), + # used in console hints such as the set_web_password() one. + CLIENT_NAME: str | None = None + HAS_TOMO_QUEUE = True HAS_EPS_STATUS = True TOMO_TYPES = { @@ -816,7 +820,8 @@ class WebpageGeneratorBase: _BOLD_RED = "\033[1;31m" _RESET = "\033[0m" print(f"{_BOLD_RED}***\nWebpageGenerator: '{current_account}' has no web authentication yet.{_RESET}") - print(f"{_BOLD_RED} To set a password run: flomni.set_web_password(\"your_password\")\n***{_RESET}") + prefix = f"{self.CLIENT_NAME}." if self.CLIENT_NAME else "" + print(f"{_BOLD_RED} To set a password run: {prefix}set_web_password(\"your_password\")\n***{_RESET}") def _clear_session_htpasswd(self) -> None: """Write an empty session.htpasswd locally and upload it.""" @@ -835,7 +840,7 @@ class WebpageGeneratorBase: The username is taken from bec.active_account (e.g. 'p23092'). Example:: - flomni.webpage_gen.set_web_password("my_secret_password") + flomni.set_web_password("my_secret_password") """ if self._set_password_url is None: print("set_web_password: no upload URL configured — cannot reach server") diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py index 2e9dae97..7538e26c 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_webpage_generator.py @@ -54,6 +54,8 @@ class FlomniWebpageGenerator(WebpageGeneratorBase): Logo: flOMNI.png from the same directory as this file. """ + CLIENT_NAME = "flomni" + # Global-var names of the tomo parameters to read live for the # 'Current measurement' section. Kept in the same order as, and matching, # the tomo queue's TQ_PARAM_DISPLAY keys so the two render identically. diff --git a/tests/tests_bec_ipython_client/test_webpage_password_hint.py b/tests/tests_bec_ipython_client/test_webpage_password_hint.py new file mode 100644 index 00000000..7d46da88 --- /dev/null +++ b/tests/tests_bec_ipython_client/test_webpage_password_hint.py @@ -0,0 +1,35 @@ +"""The 'no web authentication' hint names the setup's own client object.""" + +import types + +import pytest + +from csaxs_bec.bec_ipython_client.plugins.flomni.flomni_webpage_generator import ( + FlomniWebpageGenerator, +) +from csaxs_bec.bec_ipython_client.plugins.LamNI.LamNI_webpage_generator import ( + LamniWebpageGenerator, +) +from csaxs_bec.bec_ipython_client.plugins.OMNY_shared.webpage_generator_base import ( + WebpageGeneratorBase, +) + + +@pytest.mark.parametrize( + "cls, expected", + [ + (LamniWebpageGenerator, 'lamni.set_web_password("your_password")'), + (FlomniWebpageGenerator, 'flomni.set_web_password("your_password")'), + (WebpageGeneratorBase, 'run: set_web_password("your_password")'), + ], +) +def test_password_hint_uses_client_name(cls, expected, capsys): + gen = object.__new__(cls) + gen._session_query_url = "http://example.invalid/session.php" + gen._bec = types.SimpleNamespace(active_account="p12345") + gen._get_remote_session_user = lambda: None + gen._check_session_user() + out = capsys.readouterr().out + assert expected in out + if cls is not FlomniWebpageGenerator: + assert "flomni." not in out