passerelle/tests/test_cron.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
874 B
Python
Raw Permalink Normal View History

from unittest import mock
2022-09-29 15:29:51 +02:00
import pytest
from django.core.management import call_command
from django.core.management.base import CommandError
from passerelle.apps.base_adresse.models import BaseAdresse
2021-02-20 16:26:01 +01:00
def test_cron_frequencies(db):
2023-10-30 16:27:37 +01:00
for frequency in ('every5min', 'hourly', 'daily', 'weekly', 'monthly'):
call_command('cron', frequency)
with pytest.raises(CommandError):
call_command('cron', 'randomly')
def test_cron_error(db, caplog):
BaseAdresse.objects.create(slug='base-adresse')
excep = Exception('hello')
with mock.patch(
2021-08-15 22:28:58 +02:00
'passerelle.apps.base_adresse.models.AddressResource.hourly', new=mock.Mock(side_effect=excep)
):
with pytest.raises(CommandError):
call_command('cron', 'hourly')
assert caplog.records[0].message == 'connector "base-adresse.base-adresse" error running hourly job'