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