From b3e42f5fb04b992187cc1e01ea0b6b8d80953ced Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 17 May 2022 00:13:39 +0200 Subject: [PATCH] Add tests for offloading --- InvenTree/InvenTree/test_tasks.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/InvenTree/InvenTree/test_tasks.py b/InvenTree/InvenTree/test_tasks.py index 0b6cd08ae1..1502037dba 100644 --- a/InvenTree/InvenTree/test_tasks.py +++ b/InvenTree/InvenTree/test_tasks.py @@ -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)