From d390fd6bea769d1b39e4403c54b74c9862b0bece Mon Sep 17 00:00:00 2001 From: Sciator <39964450+Sciator@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:12:02 +0100 Subject: [PATCH] test: find_tasks_iter --- tests/test_TasksApi.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_TasksApi.py b/tests/test_TasksApi.py index 2bea7659..862abde2 100644 --- a/tests/test_TasksApi.py +++ b/tests/test_TasksApi.py @@ -184,6 +184,32 @@ def test_find_task_by_user_id(self): print(tasks) self.assertEqual(len(tasks), 1) + def test_find_tasks_iter(self): + task_name = self.generate_name("it task") + num_of_tasks = 10 + + for _ in range(num_of_tasks): + self.tasks_api.create_task_cron(task_name, TASK_FLUX, "0 2 * * *", self.organization.id) + + def count_unique_ids(tasks): + return len(set(map(lambda task: task.id, tasks))) + + # get tasks in 3-4 batches + tasks = self.tasks_api.find_tasks_iter(name= task_name, limit= num_of_tasks // 3) + self.assertEqual(count_unique_ids(tasks), num_of_tasks) + + # get tasks in one equaly size batch + tasks = self.tasks_api.find_tasks_iter(name= task_name, limit= num_of_tasks) + self.assertEqual(count_unique_ids(tasks), num_of_tasks) + + # get tasks in one batch + tasks = self.tasks_api.find_tasks_iter(name= task_name, limit= num_of_tasks + 1) + self.assertEqual(count_unique_ids(tasks), num_of_tasks) + + # get no tasks + tasks = self.tasks_api.find_tasks_iter(name= task_name + "blah") + self.assertEqual(count_unique_ids(tasks), 0) + def test_delete_task(self): task = self.tasks_api.create_task_cron(self.generate_name("it_task"), TASK_FLUX, "0 2 * * *", self.organization.id)