mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Add test for extracting request_id in __call__
Tasks will fail if we leave the kwarg in, so I think it's quite important that we test this works. We don't cover this in any other test because we call the task functions directly, so the request_id kwarg doesn't get injected beforehand.
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flask import g
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
from app import notify_celery
|
from app import notify_celery
|
||||||
|
|
||||||
|
|
||||||
|
# requiring notify_api ensures notify_celery.init_app has been called
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def celery_task():
|
def celery_task(notify_api):
|
||||||
@notify_celery.task(name=uuid.uuid4(), base=notify_celery.task_cls)
|
@notify_celery.task(name=uuid.uuid4(), base=notify_celery.task_cls)
|
||||||
def test_task(delivery_info=None): pass
|
def test_task(delivery_info=None): pass
|
||||||
return test_task
|
return test_task
|
||||||
@@ -74,3 +76,10 @@ def test_failure_queue_when_applied_synchronously(mocker, notify_api, celery_tas
|
|||||||
|
|
||||||
statsd.assert_called_once_with(f'celery.none.{celery_task.name}.failure')
|
statsd.assert_called_once_with(f'celery.none.{celery_task.name}.failure')
|
||||||
logger.assert_called_once_with(f'Celery task {celery_task.name} (queue: none) failed')
|
logger.assert_called_once_with(f'Celery task {celery_task.name} (queue: none) failed')
|
||||||
|
|
||||||
|
|
||||||
|
def test_call_exports_request_id_from_kwargs(mocker, celery_task):
|
||||||
|
g = mocker.patch('app.celery.celery.g')
|
||||||
|
# this would fail if the kwarg was passed through unexpectedly
|
||||||
|
celery_task(request_id='1234')
|
||||||
|
assert g.request_id == '1234'
|
||||||
|
|||||||
Reference in New Issue
Block a user