Exemple #1
0
def test_replay_created_notifications_create_letters_pdf_tasks_for_letters_not_ready_to_send(
        sample_letter_template, mocker):
    mock_task = mocker.patch(
        'app.celery.scheduled_tasks.create_letters_pdf.apply_async')
    create_notification(template=sample_letter_template,
                        billable_units=0,
                        created_at=datetime.utcnow() - timedelta(hours=4))

    create_notification(template=sample_letter_template,
                        billable_units=0,
                        created_at=datetime.utcnow() - timedelta(minutes=20))
    notification_1 = create_notification(template=sample_letter_template,
                                         billable_units=0,
                                         created_at=datetime.utcnow() -
                                         timedelta(hours=1, minutes=20))
    notification_2 = create_notification(template=sample_letter_template,
                                         billable_units=0,
                                         created_at=datetime.utcnow() -
                                         timedelta(hours=5))

    replay_created_notifications()

    calls = [
        call([notification_1.id], queue=QueueNames.LETTERS),
        call([notification_2.id], queue=QueueNames.LETTERS),
    ]
    mock_task.assert_has_calls(calls, any_order=True)
def test_replay_created_notifications(notify_db_session, sample_service, mocker):
    email_delivery_queue = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
    sms_delivery_queue = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')

    sms_template = create_template(service=sample_service, template_type='sms')
    email_template = create_template(service=sample_service, template_type='email')
    older_than = (60 * 60) + (60 * 15)  # 1 hour 15 minutes
    # notifications expected to be resent
    old_sms = create_notification(template=sms_template, created_at=datetime.utcnow() - timedelta(seconds=older_than),
                                  status='created')
    old_email = create_notification(template=email_template,
                                    created_at=datetime.utcnow() - timedelta(seconds=older_than),
                                    status='created')
    # notifications that are not to be resent
    create_notification(template=sms_template, created_at=datetime.utcnow() - timedelta(seconds=older_than),
                        status='sending')
    create_notification(template=email_template, created_at=datetime.utcnow() - timedelta(seconds=older_than),
                        status='delivered')
    create_notification(template=sms_template, created_at=datetime.utcnow(),
                        status='created')
    create_notification(template=email_template, created_at=datetime.utcnow(),
                        status='created')

    replay_created_notifications()
    email_delivery_queue.assert_called_once_with([str(old_email.id)],
                                                 queue='send-email-tasks')
    sms_delivery_queue.assert_called_once_with([str(old_sms.id)],
                                               queue="send-sms-tasks")