add checks for old_error_log

This commit is contained in:
Matthias 2022-05-16 23:42:09 +02:00
parent f3c4720f5b
commit 09bda7e516
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -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