* refactor: Change import style for clarity * feat: Add iana_changes_updates_task() * chore: Squelch lint warning My linter does not like variables defined outside of __init__() * feat: Add PeriodicTask for iana_changes_updates_task * refactor: tasks instead of scripts on sync.views.notify() * test: Test iana_changes_updates_task * refactor: rename task for consistency * feat: Add iana_protocols_update_task * feat: Add PeriodicTask for iana protocols sync * refactor: Use protocol sync task instead of script in view * refactor: itertools.batched() not available until py312 * test: test iana_protocols_update_task * feat: Add idindex_update_task() Calls idindex generation functions and does the file update dance to put them in place. * chore: Add comments to bin/hourly * fix: annotate types and fix bug * feat: Create PeriodicTask for idindex_update_task * refactor: Move helpers into a class More testable this way * refactor: Make TempFileManager a context mgr * test: Test idindex_update_task * test: Test TempFileManager * fix: Fix bug in TestFileManager yay testing * feat: Add expire_ids_task() * feat: Create PeriodicTask for expire_ids_task * test: Test expire_ids_task * test: Test request timeout in iana_protocols_update_task * refactor: do not re-raise timeout exception Not sure this is the right thing to do, but it's the same as rfc_editor_index_update_task * feat: Add notify_expirations_task * feat: Add "weekly" celery beat crontab * refactor: Reorder crontab fields This matches the crontab file field order * feat: Add PeriodicTask for notify_expirations * test: Test notify_expirations_task * test: Add annotation to satisfy mypy
64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
# Copyright The IETF Trust 2024, All Rights Reserved
|
|
import mock
|
|
|
|
from ietf.utils.test_utils import TestCase
|
|
from ietf.utils.timezone import datetime_today
|
|
|
|
from .factories import DocumentFactory
|
|
from .models import Document
|
|
from .tasks import expire_ids_task, notify_expirations_task
|
|
|
|
|
|
class TaskTests(TestCase):
|
|
|
|
@mock.patch("ietf.doc.tasks.in_draft_expire_freeze")
|
|
@mock.patch("ietf.doc.tasks.get_expired_drafts")
|
|
@mock.patch("ietf.doc.tasks.expirable_drafts")
|
|
@mock.patch("ietf.doc.tasks.send_expire_notice_for_draft")
|
|
@mock.patch("ietf.doc.tasks.expire_draft")
|
|
@mock.patch("ietf.doc.tasks.clean_up_draft_files")
|
|
def test_expire_ids_task(
|
|
self,
|
|
clean_up_draft_files_mock,
|
|
expire_draft_mock,
|
|
send_expire_notice_for_draft_mock,
|
|
expirable_drafts_mock,
|
|
get_expired_drafts_mock,
|
|
in_draft_expire_freeze_mock,
|
|
):
|
|
# set up mocks
|
|
in_draft_expire_freeze_mock.return_value = False
|
|
doc, other_doc = DocumentFactory.create_batch(2)
|
|
doc.expires = datetime_today()
|
|
get_expired_drafts_mock.return_value = [doc, other_doc]
|
|
expirable_drafts_mock.side_effect = [
|
|
Document.objects.filter(pk=doc.pk),
|
|
Document.objects.filter(pk=other_doc.pk),
|
|
]
|
|
|
|
# call task
|
|
expire_ids_task()
|
|
|
|
# check results
|
|
self.assertTrue(in_draft_expire_freeze_mock.called)
|
|
self.assertEqual(expirable_drafts_mock.call_count, 2)
|
|
self.assertEqual(send_expire_notice_for_draft_mock.call_count, 1)
|
|
self.assertEqual(send_expire_notice_for_draft_mock.call_args[0], (doc,))
|
|
self.assertEqual(expire_draft_mock.call_count, 1)
|
|
self.assertEqual(expire_draft_mock.call_args[0], (doc,))
|
|
self.assertTrue(clean_up_draft_files_mock.called)
|
|
|
|
# test that an exception is raised
|
|
in_draft_expire_freeze_mock.side_effect = RuntimeError
|
|
with self.assertRaises(RuntimeError):(
|
|
expire_ids_task())
|
|
|
|
@mock.patch("ietf.doc.tasks.send_expire_warning_for_draft")
|
|
@mock.patch("ietf.doc.tasks.get_soon_to_expire_drafts")
|
|
def test_notify_expirations_task(self, get_drafts_mock, send_warning_mock):
|
|
# Set up mocks
|
|
get_drafts_mock.return_value = ["sentinel"]
|
|
notify_expirations_task()
|
|
self.assertEqual(send_warning_mock.call_count, 1)
|
|
self.assertEqual(send_warning_mock.call_args[0], ("sentinel",))
|