From 09bda7e516b247cbc69541fa9e3339d7663488d9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 May 2022 23:42:09 +0200 Subject: [PATCH] add checks for old_error_log --- InvenTree/InvenTree/test_tasks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/InvenTree/InvenTree/test_tasks.py b/InvenTree/InvenTree/test_tasks.py index 74eee7c73d..9952eccff4 100644 --- a/InvenTree/InvenTree/test_tasks.py +++ b/InvenTree/InvenTree/test_tasks.py @@ -8,10 +8,16 @@ from django.utils import timezone from django.test import TestCase from django_q.models import Schedule +from error_report.models import Error + import InvenTree.tasks from common.models import InvenTreeSetting +threshold = timezone.now() - timedelta(days=30) +threshold_low = threshold - timedelta(days=1) + + class ScheduledTaskTests(TestCase): """ Unit tests for scheduled tasks @@ -72,8 +78,23 @@ class InvenTreeTaskTests(TestCase): def test_task_delete_old_error_logs(self): """Test the task delete_old_error_logs""" + + # Create error + error_obj = Error.objects.create() + error_obj.when = threshold_low + error_obj.save() + + # Check that it is not empty + errors = Error.objects.filter(when__lte=threshold,) + self.assertNotEqual(len(errors), 0) + + # Run action InvenTree.tasks.offload_task(InvenTree.tasks.delete_old_error_logs) + # Check that it is empty again + errors = Error.objects.filter(when__lte=threshold,) + self.assertEqual(len(errors), 0) + def test_task_check_for_updates(self): """Test the task check_for_updates""" # Check that setting should be empty