Skip to content

Commit

Permalink
test: find_tasks_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Nov 22, 2023
1 parent 213860d commit d390fd6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_TasksApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d390fd6

Please sign in to comment.