mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Merge branch 'master' into letter-deskpro-ack-mod
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
@@ -10,9 +11,11 @@ from app.models import (
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
NOTIFICATION_TECHNICAL_FAILURE
|
||||
)
|
||||
from app.celery.tasks import (
|
||||
check_billable_units,
|
||||
process_updates_from_file,
|
||||
update_dvla_job_to_error,
|
||||
update_job_to_sent_to_dvla,
|
||||
@@ -25,6 +28,15 @@ from tests.app.db import create_notification, create_service_callback_api
|
||||
from tests.conftest import set_config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def notification_update():
|
||||
"""
|
||||
Returns a namedtuple to use as the argument for the check_billable_units function
|
||||
"""
|
||||
NotificationUpdate = namedtuple('NotificationUpdate', ['reference', 'status', 'page_count', 'cost_threshold'])
|
||||
return NotificationUpdate('REFERENCE_ABC', 'sent', '1', 'cost')
|
||||
|
||||
|
||||
def test_update_job_to_sent_to_dvla(sample_letter_template, sample_letter_job):
|
||||
create_notification(template=sample_letter_template, job=sample_letter_job)
|
||||
create_notification(template=sample_letter_template, job=sample_letter_job)
|
||||
@@ -107,7 +119,7 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
|
||||
assert sent_letter.status == NOTIFICATION_DELIVERED
|
||||
assert sent_letter.billable_units == 1
|
||||
assert sent_letter.updated_at
|
||||
assert failed_letter.status == NOTIFICATION_TECHNICAL_FAILURE
|
||||
assert failed_letter.status == NOTIFICATION_TEMPORARY_FAILURE
|
||||
assert failed_letter.billable_units == 2
|
||||
assert failed_letter.updated_at
|
||||
|
||||
@@ -162,3 +174,37 @@ def test_update_letter_notifications_to_error_updates_based_on_notification_refe
|
||||
assert first.sent_at is None
|
||||
assert first.updated_at == dt
|
||||
assert second.status == NOTIFICATION_CREATED
|
||||
|
||||
|
||||
def test_check_billable_units_when_billable_units_matches_page_count(
|
||||
client,
|
||||
sample_letter_template,
|
||||
mocker,
|
||||
notification_update
|
||||
):
|
||||
mock_logger = mocker.patch('app.celery.tasks.current_app.logger.error')
|
||||
|
||||
notification = create_notification(sample_letter_template, reference='REFERENCE_ABC')
|
||||
notification.billable_units = 1
|
||||
|
||||
check_billable_units(notification_update)
|
||||
|
||||
mock_logger.assert_not_called()
|
||||
|
||||
|
||||
def test_check_billable_units_when_billable_units_does_not_match_page_count(
|
||||
client,
|
||||
sample_letter_template,
|
||||
mocker,
|
||||
notification_update
|
||||
):
|
||||
mock_logger = mocker.patch('app.celery.tasks.current_app.logger.error')
|
||||
|
||||
notification = create_notification(sample_letter_template, reference='REFERENCE_ABC')
|
||||
notification.billable_units = 3
|
||||
|
||||
check_billable_units(notification_update)
|
||||
|
||||
mock_logger.assert_called_once_with(
|
||||
'Notification with id {} had 3 billable_units but a page count of 1'.format(notification.id)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user