about summary refs log tree commit diff
path: root/test/python/test_group_strains.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/python/test_group_strains.py')
-rw-r--r--test/python/test_group_strains.py42
1 files changed, 20 insertions, 22 deletions
diff --git a/test/python/test_group_strains.py b/test/python/test_group_strains.py
index 12b4aa4..91cc7fb 100644
--- a/test/python/test_group_strains.py
+++ b/test/python/test_group_strains.py
@@ -1,6 +1,7 @@
-"""Mirrors tests/group_strains.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_strains.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,17 +22,25 @@ def database_reachable():
 
 
 class GroupStrainsTest(ServerTestCase):
-    def test_group_strains_bxd_returns_strains(self):
-        if not database_reachable():
-            self.skipTest("no database on 127.0.0.1:3306")
+    EXTRA_ENV = TOKEN_ENV
 
+    def get(self, path):
+        token = auth_token()
+        if not token:
+            self.skipTest("no token (see docs/gn-auth.md)")
         conn = http.client.HTTPConnection(HOST, int(PORT), timeout=10)
         try:
-            conn.request("GET", "/groups/BXD/strains")
+            conn.request("GET", path, headers={"Authorization": f"Bearer {token}"})
             response = conn.getresponse()
-            body = response.read()
+            return response, response.read()
         finally:
             conn.close()
+
+    def test_group_strains_bxd_returns_strains(self):
+        if not database_reachable():
+            self.skipTest("no database on 127.0.0.1:3306")
+
+        response, body = self.get("/groups/BXD/strains")
         self.assertEqual(response.status, 200)
 
         strains = json.loads(body)
@@ -42,13 +52,7 @@ class GroupStrainsTest(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/BXD/strains?used_for_mapping=true")
-            response = conn.getresponse()
-            body = response.read()
-        finally:
-            conn.close()
+        response, body = self.get("/groups/BXD/strains?used_for_mapping=true")
         self.assertEqual(response.status, 200)
 
         strains = json.loads(body)
@@ -61,13 +65,7 @@ class GroupStrainsTest(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/strains")
-            response = conn.getresponse()
-            body = response.read()
-        finally:
-            conn.close()
+        response, body = self.get("/groups/not-a-real-group/strains")
         self.assertEqual(response.status, 404)
 
         error = json.loads(body)