diff options
Diffstat (limited to 'test/python/test_dataset_probesets.py')
| -rw-r--r-- | test/python/test_dataset_probesets.py | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/test/python/test_dataset_probesets.py b/test/python/test_dataset_probesets.py index 64cebff..dcfcd99 100644 --- a/test/python/test_dataset_probesets.py +++ b/test/python/test_dataset_probesets.py @@ -1,21 +1,20 @@ """Mirrors tests/dataset_probesets.rs. Needs a live MariaDB (SQL_URI); skips with a message rather than failing when none is reachable, same as test_group_by_name.py. Also needs a live gn-auth (AUTH_SERVER_URL) -and GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md), since this endpoint now -requires a bearer token; skips when either is missing. +and a token (see docs/gn-auth.md), since this endpoint now requires a +bearer token; skips when either is missing. auth_token() tries this +server's own POST /get-test-token first (EXTRA_ENV below makes that +possible), falling back to GN4_TEST_AUTH_TOKEN. """ import http.client import json -import os import socket import unittest -from urllib.parse import urlparse +from auth_helpers import TOKEN_ENV, auth_server_reachable, auth_token from server_test_case import HOST, PORT, ServerTestCase -AUTH_SERVER_URL = os.environ.get("AUTH_SERVER_URL", "http://127.0.0.1:8081/") - def database_reachable(): try: @@ -25,30 +24,16 @@ def database_reachable(): return False -def auth_server_reachable(): - url = urlparse(AUTH_SERVER_URL) - conn = http.client.HTTPConnection(url.hostname, url.port or 80, timeout=2) - try: - conn.request("GET", url.path.rstrip("/") + "/auth/public-jwks") - return conn.getresponse().status == 200 - except OSError: - return False - finally: - conn.close() - - -def auth_token(): - return os.environ.get("GN4_TEST_AUTH_TOKEN") - - class DatasetProbesetsTest(ServerTestCase): + EXTRA_ENV = TOKEN_ENV + def require_fixtures(self): if not database_reachable(): self.skipTest("no database on 127.0.0.1:3306") if not auth_token(): - self.skipTest("set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)") + self.skipTest("no token (see docs/gn-auth.md)") if not auth_server_reachable(): - self.skipTest(f"no gn-auth reachable at {AUTH_SERVER_URL}") + self.skipTest("no gn-auth reachable") def get(self, path, with_token=True): conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10) |
