| 1 |
from unittest.mock import patch |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
|
| 6 |
@pytest.mark.patched_module( |
| 7 |
'django', |
| 8 |
'django.db', |
| 9 |
'django.db.transaction', |
| 10 |
) |
| 11 |
@pytest.mark.usefixtures("module") |
| 12 |
class test_DjangoTask: |
| 13 |
@pytest.fixture |
| 14 |
def task_instance(self): |
| 15 |
from celery.contrib.django.task import DjangoTask |
| 16 |
yield DjangoTask() |
| 17 |
|
| 18 |
@pytest.fixture(name="on_commit") |
| 19 |
def on_commit(self): |
| 20 |
with patch( |
| 21 |
'django.db.transaction.on_commit', |
| 22 |
side_effect=lambda f: f(), |
| 23 |
) as patched_on_commit: |
| 24 |
yield patched_on_commit |
| 25 |
|
| 26 |
def test_delay_on_commit(self, task_instance, on_commit): |
| 27 |
result = task_instance.delay_on_commit() |
| 28 |
assert result is None |
| 29 |
|
| 30 |
def test_apply_async_on_commit(self, task_instance, on_commit): |
| 31 |
result = task_instance.apply_async_on_commit() |
| 32 |
assert result is None |