about summary refs log tree commit diff
path: root/test/python/test_group_traits.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/python/test_group_traits.py')
-rw-r--r--test/python/test_group_traits.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/test/python/test_group_traits.py b/test/python/test_group_traits.py
index e414e7e..d918688 100644
--- a/test/python/test_group_traits.py
+++ b/test/python/test_group_traits.py
@@ -1,6 +1,7 @@
-"""Mirrors tests/group_traits.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.
+"""Mirrors tests/group_traits.rs. Needs a live MariaDB (SQL_URI) and a
+valid token (every endpoint needs one now -- see docs/gn-auth.md);
+skips with a message rather than failing when either is missing, same
+as test_group_by_name.py.
 """
 
 import http.client
@@ -8,6 +9,7 @@ import json
 import socket
 import unittest
 
+from auth_helpers import TOKEN_ENV, auth_token
 from server_test_case import HOST, PORT, ServerTestCase
 
 
@@ -20,6 +22,20 @@ def database_reachable():
 
 
 class GroupTraitsTest(ServerTestCase):
+    EXTRA_ENV = TOKEN_ENV
+
+    def get(self, path, timeout=10):
+        token = auth_token()
+        if not token:
+            self.skipTest("no token (see docs/gn-auth.md)")
+        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=timeout)
+        try:
+            conn.request("GET", path, headers={"Authorization": f"Bearer {token}"})
+            response = conn.getresponse()
+            return response, response.read()
+        finally:
+            conn.close()
+
     def test_group_traits_bxd_returns_traits(self):
         if not database_reachable():
             self.skipTest("no database on 127.0.0.1:3306")
@@ -27,13 +43,7 @@ class GroupTraitsTest(ServerTestCase):
         # BXD alone has 15000+ phenotype traits (a ~17MB response);
         # fetching all of them can take longer than the default 10s
         # used elsewhere in this test suite.
-        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=30)
-        try:
-            conn.request("GET", "/groups/BXD/traits")
-            response = conn.getresponse()
-            body = response.read()
-        finally:
-            conn.close()
+        response, body = self.get("/groups/BXD/traits", timeout=30)
         self.assertEqual(response.status, 200)
 
         traits = json.loads(body)
@@ -45,13 +55,7 @@ class GroupTraitsTest(ServerTestCase):
         if not database_reachable():
             self.skipTest("no database on 127.0.0.1:3306")
 
-        conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10)
-        try:
-            conn.request("GET", "/groups/not-a-real-group/traits")
-            response = conn.getresponse()
-            body = response.read()
-        finally:
-            conn.close()
+        response, body = self.get("/groups/not-a-real-group/traits")
         self.assertEqual(response.status, 404)
 
         error = json.loads(body)