From 5fa7b45d1dcb295a1d76fa0bf9c6994d656b76b7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 3 May 2022 21:39:45 +0200 Subject: [PATCH] Add tests for scheduling Closes #2523 --- .../integration/test_scheduled_task.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 InvenTree/plugin/samples/integration/test_scheduled_task.py diff --git a/InvenTree/plugin/samples/integration/test_scheduled_task.py b/InvenTree/plugin/samples/integration/test_scheduled_task.py new file mode 100644 index 0000000000..4df357df29 --- /dev/null +++ b/InvenTree/plugin/samples/integration/test_scheduled_task.py @@ -0,0 +1,29 @@ +""" Unit tests for scheduled tasks""" + +from django.test import TestCase + +from plugin import registry + + +class ScheduledTaskPluginTests(TestCase): + """ Tests for ScheduledTaskPlugin """ + + def test_function(self): + """check if the scheduling works""" + # The plugin should be defined + self.assertIn('schedule', registry.plugins) + plg = registry.plugins['schedule'] + self.assertTrue(plg) + + # check that the built-in function is running + plg.member_func() + + # check that the tasks are defined + self.assertEqual(plg.get_task_names(), ['plugin.schedule.member', 'plugin.schedule.hello', 'plugin.schedule.world']) + + # register + plg.register_tasks() + # check that schedule was registers + from django_q.models import Schedule + scheduled_plugin_tasks = Schedule.objects.filter(name__istartswith="plugin.") + self.assertEqual(len(scheduled_plugin_tasks), 3)