Skip to content

Commit 22c3382

Browse files
author
marekbiczysko
committed
ut
1 parent c2b1453 commit 22c3382

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tests/unit/apps/core/test_core_celery_tasks.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,29 @@ def test_upload_kobo_template_with_retry_sets_unsuccessful_when_failed_time_is_o
6666

6767

6868
def test_upload_kobo_template_with_retry_retries_when_failed_time_is_recent(xlsx_kobo_template):
69-
# With CELERY_TASK_ALWAYS_EAGER=True, self.retry() re-runs the task eagerly.
70-
# After max_retries are exhausted, the original exc (KoboRetriableError) is re-raised.
7169
xlsx_kobo_template.first_connection_failed_time = timezone.now() - timedelta(minutes=30)
7270
exc = KoboRetriableError(xlsx_kobo_template)
7371

7472
mock_instance = MagicMock()
7573
mock_instance.execute.side_effect = exc
7674
mock_task_cls = MagicMock(return_value=mock_instance)
7775

78-
with patch(
79-
"hope.apps.core.tasks.upload_new_template_and_update_flex_fields.UploadNewKoboTemplateAndUpdateFlexFieldsTask",
80-
mock_task_cls,
76+
with (
77+
patch(
78+
"hope.apps.core.tasks.upload_new_template_and_update_flex_fields.UploadNewKoboTemplateAndUpdateFlexFieldsTask",
79+
mock_task_cls,
80+
),
81+
patch(
82+
"hope.apps.core.celery_tasks.upload_new_kobo_template_and_update_flex_fields_task_with_retry_async_task"
83+
) as mock_retry_task,
8184
):
8285
job = AsyncRetryJob.objects.create(
8386
type="JOB_TASK",
8487
action="hope.apps.core.celery_tasks.upload_new_kobo_template_and_update_flex_fields_task_with_retry_async_task_action",
8588
config={"xlsx_kobo_template_id": str(xlsx_kobo_template.id)},
8689
)
87-
with pytest.raises(KoboRetriableError):
88-
upload_new_kobo_template_and_update_flex_fields_task_with_retry_async_task_action(job)
90+
upload_new_kobo_template_and_update_flex_fields_task_with_retry_async_task_action(job)
91+
92+
job.refresh_from_db()
93+
assert job.errors == {"exception": str(exc)}
94+
mock_retry_task.assert_called_once_with(str(xlsx_kobo_template.id))

0 commit comments

Comments
 (0)