gva/gnuviechadmin/taskresults/tests/testutils.py
Jan Dittberner 610f8976fc Refactor managemails to use signals
- use signals to trigger Celery tasks to create and delete mailboxes
- add generic TestCaseWithCeleryTasks class to handle celery task tests
  in a uniform way
2023-02-19 13:45:30 +01:00

21 lines
676 B
Python

from django.test import TestCase
from django.test.utils import override_settings
from taskresults.models import TaskResult
@override_settings(
CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND="memory", BROKER_BACKEND="memory"
)
class TestCaseWithCeleryTasks(TestCase):
def resetCeleryTasks(self):
TaskResult.objects.all().delete()
def assertCeleryTasksRun(self, tasks):
task_results = TaskResult.objects.all()
self.assertEqual(task_results.count(), sum([t[0] for t in tasks]))
creators = [r.creator for r in task_results]
for t_count, t_creator in tasks:
self.assertEqual(creators.count(t_creator), t_count)