about summary refs log tree commit diff
path: root/test/python/test_traits.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/python/test_traits.py')
-rw-r--r--test/python/test_traits.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/test/python/test_traits.py b/test/python/test_traits.py
index 97603ba..38bf411 100644
--- a/test/python/test_traits.py
+++ b/test/python/test_traits.py
@@ -1,20 +1,19 @@
 """Mirrors tests/traits.rs. Needs a live MariaDB (SQL_URI) and a live
-gn-auth (AUTH_SERVER_URL) plus GN4_TEST_AUTH_TOKEN (see
-docs/gn-auth.md); skips when any is missing, same as
-test_dataset_probeset_info.py.
+gn-auth (AUTH_SERVER_URL) plus a token (see docs/gn-auth.md); skips
+when any is missing, same as test_dataset_probeset_info.py.
+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:
@@ -24,30 +23,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 TraitsTest(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)