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
This commit is contained in:
parent
d6fc29a2b8
commit
610f8976fc
5 changed files with 114 additions and 37 deletions
21
gnuviechadmin/taskresults/tests/testutils.py
Normal file
21
gnuviechadmin/taskresults/tests/testutils.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue