Add tests for offloading

This commit is contained in:
Matthias 2022-05-17 00:13:39 +02:00
parent 3e859f7abb
commit b3e42f5fb0
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -53,9 +53,31 @@ class ScheduledTaskTests(TestCase):
self.assertEqual(t.minutes, 5)
def get_result():
"""Demo function for test_offloading"""
return 'abc'
class InvenTreeTaskTests(TestCase):
"""Unit tests for tasks"""
def test_offloading(self):
"""Test task offloading"""
# Run with function ref
InvenTree.tasks.offload_task(get_result)
# Run with string ref
InvenTree.tasks.offload_task('InvenTree.test_tasks.get_result')
# Error runs
# Malformed taskname
InvenTree.tasks.offload_task('InvenTree')
# Non exsistent app
InvenTree.tasks.offload_task('InvenTreeABC.test_tasks.doesnotmatter')
# Non exsistent function
InvenTree.tasks.offload_task('InvenTree.test_tasks.doesnotexsist')
def test_task_hearbeat(self):
"""Test the task heartbeat"""
InvenTree.tasks.offload_task(InvenTree.tasks.heartbeat)