feat(OMNY): register test-account measurements against the test server
TomoIDManager.register() used to skip OMNY registration entirely for any non-e-account (e.g. test accounts), always returning the tomo ID 0 fallback. Register against a new TEST_OMNY_URL (omny-test.psi.ch) instead for those accounts, so testing still gets a real, incrementing tomo ID matching the counter the samples-folder PDF upload reads from on that same host -- accepting a mismatched eaccount in that test database. FALLBACK_TOMO_ID is now reserved for genuine failures (server unreachable), not merely a non-standard account name.
This commit is contained in:
@@ -329,8 +329,12 @@ class TomoIDManager:
|
||||
"""Registers a tomography measurement in the OMNY sample database
|
||||
and returns its assigned tomo ID.
|
||||
|
||||
Falls back to tomo ID 0 for non-production accounts (e.g. test
|
||||
accounts like "gac-x01dc") which the server rejects.
|
||||
Non-production accounts (e.g. test accounts like "gac-x01dc") register
|
||||
against the test server (TEST_OMNY_URL) instead of production, so
|
||||
testing still gets a real, incrementing tomo ID -- matching the
|
||||
counter the samples-folder PDF upload reads from on that same test
|
||||
host -- accepting that the eaccount recorded in that test database
|
||||
won't be a real e-account.
|
||||
|
||||
Usage:
|
||||
id_manager = TomoIDManager()
|
||||
@@ -346,6 +350,7 @@ class TomoIDManager:
|
||||
"""
|
||||
|
||||
OMNY_URL = "https://v1p0zyg2w9n2k9c1.myfritz.net/samples/newmeasurement.php"
|
||||
TEST_OMNY_URL = "https://omny-test.psi.ch/samples/newmeasurement.php"
|
||||
TMP_FILE = "~/currsamplesnr.txt"
|
||||
FALLBACK_TOMO_ID = 0
|
||||
|
||||
@@ -366,18 +371,23 @@ class TomoIDManager:
|
||||
) -> int:
|
||||
"""Register a new measurement and return the assigned tomo ID.
|
||||
|
||||
Returns FALLBACK_TOMO_ID (0) if the account is not a real e-account
|
||||
or if the server cannot be reached / returns an unusable response.
|
||||
Registers against OMNY_URL (production) for a real e-account, or
|
||||
TEST_OMNY_URL (test server) otherwise. Returns FALLBACK_TOMO_ID (0)
|
||||
only if the server actually can't be reached / returns an unusable
|
||||
response.
|
||||
"""
|
||||
if not self._is_valid_eaccount(eaccount):
|
||||
if self._is_valid_eaccount(eaccount):
|
||||
omny_url = self.OMNY_URL
|
||||
else:
|
||||
omny_url = self.TEST_OMNY_URL
|
||||
logger.warning(
|
||||
f"Account '{eaccount}' is not a valid e-account; "
|
||||
f"skipping OMNY registration, using tomo ID {self.FALLBACK_TOMO_ID}."
|
||||
f"Account '{eaccount}' is not a valid e-account; registering "
|
||||
f"against the test server ({self.TEST_OMNY_URL}) instead of "
|
||||
"production -- the eaccount recorded there won't be real."
|
||||
)
|
||||
return self.FALLBACK_TOMO_ID
|
||||
|
||||
url = (
|
||||
f"{self.OMNY_URL}"
|
||||
f"{omny_url}"
|
||||
f"?sample={sample_name}"
|
||||
f"&date={date}"
|
||||
f"&eaccount={eaccount}"
|
||||
@@ -392,7 +402,7 @@ class TomoIDManager:
|
||||
result = subprocess.run(f"wget -q -O {tmp_file} '{url}'", shell=True, timeout=30)
|
||||
if result.returncode != 0:
|
||||
raise OMNYToolsError(
|
||||
f"wget failed (exit code {result.returncode}) fetching tomo ID from {self.OMNY_URL}"
|
||||
f"wget failed (exit code {result.returncode}) fetching tomo ID from {omny_url}"
|
||||
)
|
||||
with open(tmp_file) as f:
|
||||
content = f.read().strip()
|
||||
|
||||
Reference in New Issue
Block a user