From 97b4914ad9ce3597957c371023d2478d876e827a Mon Sep 17 00:00:00 2001
From: Matthias Mair <code@mjmair.com>
Date: Wed, 5 Feb 2025 02:09:10 +0100
Subject: [PATCH] extend info view tests

---
 src/backend/InvenTree/InvenTree/test_api.py | 44 +++++++++++++--------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/backend/InvenTree/InvenTree/test_api.py b/src/backend/InvenTree/InvenTree/test_api.py
index dff75e4388..975368f16b 100644
--- a/src/backend/InvenTree/InvenTree/test_api.py
+++ b/src/backend/InvenTree/InvenTree/test_api.py
@@ -65,8 +65,8 @@ class HTMLAPITests(InvenTreeTestCase):
             self.assertEqual(response.status_code, 404)
 
 
-class APITests(InvenTreeAPITestCase):
-    """Tests for the InvenTree API."""
+class ApiAccessTests(InvenTreeAPITestCase):
+    """Tests for various access scenarios with the InvenTree API."""
 
     fixtures = ['location', 'category', 'part', 'stock']
     roles = ['part.view']
@@ -107,19 +107,6 @@ class APITests(InvenTreeAPITestCase):
         self.tokenAuth()
         self.assertIsNotNone(self.token)
 
-    def test_info_view(self):
-        """Test that we can read the 'info-view' endpoint."""
-        url = reverse('api-inventree-info')
-
-        response = self.get(url)
-
-        data = response.json()
-        self.assertIn('server', data)
-        self.assertIn('version', data)
-        self.assertIn('instance', data)
-
-        self.assertEqual('InvenTree', data['server'])
-
     def test_role_view(self):
         """Test that we can access the 'roles' view for the logged in user.
 
@@ -431,7 +418,7 @@ class SearchTests(InvenTreeAPITestCase):
 
 
 class GeneralApiTests(InvenTreeAPITestCase):
-    """Tests for versions and license endpoints."""
+    """Tests for various api endpoints."""
 
     def test_api_version(self):
         """Test that the API text is correct."""
@@ -490,3 +477,28 @@ class GeneralApiTests(InvenTreeAPITestCase):
                 self.assertEqual(respo, [])
 
                 self.assertIn('Failed to parse license file', str(log.output))
+
+    def test_info_view(self):
+        """Test that we can read the 'info-view' endpoint."""
+        url = reverse('api-inventree-info')
+
+        response = self.get(url)
+
+        data = response.json()
+        self.assertIn('server', data)
+        self.assertIn('version', data)
+        self.assertIn('instance', data)
+
+        self.assertEqual('InvenTree', data['server'])
+
+        # Test with token
+        token = self.get(url=reverse('api-token')).data['token']
+        self.client.logout()
+
+        # Anon
+        response = self.get(url)
+        self.assertEqual(response.json()['database'], None)
+
+        # Staff
+        response = self.get(url, headers={'Authorization': f'Token {token}'})
+        self.assertGreater(len(response.json()['database']), 4)