]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix tests, warning
authorshamoon <4887959+shamoon@users.noreply.github.com>
Fri, 14 Feb 2025 04:00:35 +0000 (20:00 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Mon, 17 Feb 2025 16:19:11 +0000 (08:19 -0800)
src/documents/tests/test_api_status.py
src/documents/views.py

index 992dbff64bfc34009836bf97e999309d4569e82b..6bbb4dcb01a71b164709902883054aa6ee0ca176 100644 (file)
@@ -209,6 +209,24 @@ class TestSystemStatus(APITestCase):
         self.assertEqual(response.data["tasks"]["classifier_status"], "OK")
         self.assertIsNone(response.data["tasks"]["classifier_error"])
 
+    def test_system_status_classifier_warning(self):
+        """
+        GIVEN:
+            - No classifier task is found
+        WHEN:
+            - The user requests the system status
+        THEN:
+            - The response contains a WARNING classifier status
+        """
+        self.client.force_login(self.user)
+        response = self.client.get(self.ENDPOINT)
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.assertEqual(
+            response.data["tasks"]["classifier_status"],
+            "WARNING",
+        )
+        self.assertIsNone(response.data["tasks"]["classifier_error"])
+
     def test_system_status_classifier_error(self):
         """
         GIVEN:
@@ -253,6 +271,24 @@ class TestSystemStatus(APITestCase):
         self.assertEqual(response.data["tasks"]["sanity_check_status"], "OK")
         self.assertIsNone(response.data["tasks"]["sanity_check_error"])
 
+    def test_system_status_sanity_check_warning(self):
+        """
+        GIVEN:
+            - No sanity check task is found
+        WHEN:
+            - The user requests the system status
+        THEN:
+            - The response contains a WARNING sanity check status
+        """
+        self.client.force_login(self.user)
+        response = self.client.get(self.ENDPOINT)
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.assertEqual(
+            response.data["tasks"]["sanity_check_status"],
+            "WARNING",
+        )
+        self.assertIsNone(response.data["tasks"]["sanity_check_error"])
+
     def test_system_status_sanity_check_error(self):
         """
         GIVEN:
index 8903ff62a6e48e954e1c5b199110ad98205cab08..d9bd2f58561c1c551e2fa84bdbe5751161e34b5b 100644 (file)
@@ -2666,15 +2666,12 @@ class SystemStatusView(PassUserMixin):
             .order_by("-date_done")
             .first()
         )
-
-        classifier_status = (
-            "OK"
-            if last_trained_task is not None
-            and last_trained_task.status == states.SUCCESS
-            else "ERROR"
-        )
+        classifier_status = "OK"
         classifier_error = None
-        if last_trained_task and last_trained_task.status == states.FAILURE:
+        if last_trained_task is None:
+            classifier_status = "WARNING"
+        elif last_trained_task and last_trained_task.status == states.FAILURE:
+            classifier_status = "ERROR"
             classifier_error = last_trained_task.result
         classifier_last_trained = (
             last_trained_task.date_done if last_trained_task else None
@@ -2687,15 +2684,12 @@ class SystemStatusView(PassUserMixin):
             .order_by("-date_done")
             .first()
         )
-
-        sanity_check_status = (
-            "OK"
-            if last_sanity_check is not None
-            and last_sanity_check.status == states.SUCCESS
-            else "ERROR"
-        )
+        sanity_check_status = "OK"
         sanity_check_error = None
-        if last_sanity_check and last_sanity_check.status == states.FAILURE:
+        if last_sanity_check is None:
+            sanity_check_status = "WARNING"
+        elif last_sanity_check and last_sanity_check.status == states.FAILURE:
+            sanity_check_status = "ERROR"
             sanity_check_error = last_sanity_check.result
         sanity_check_last_run = (
             last_sanity_check.date_done if last_sanity_check else None