Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-free-sms-limit-history

This commit is contained in:
venusbb
2017-10-30 09:34:23 +00:00
7 changed files with 118 additions and 17 deletions

View File

@@ -9,12 +9,9 @@ from app.models import (
Notification,
NOTIFICATION_CREATED,
NOTIFICATION_DELIVERED,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_SENDING,
NOTIFICATION_STATUS_LETTER_RECEIVED,
NOTIFICATION_TECHNICAL_FAILURE
)
from app.dao.notifications_dao import dao_update_notifications_by_reference
from app.celery.tasks import (
process_updates_from_file,
update_dvla_job_to_error,
@@ -96,8 +93,10 @@ def test_update_letter_notifications_statuses_builds_updates_list(notify_api, mo
def test_update_letter_notifications_statuses_persisted(notify_api, mocker, sample_letter_template):
sent_letter = create_notification(sample_letter_template, reference='ref-foo', status=NOTIFICATION_SENDING)
failed_letter = create_notification(sample_letter_template, reference='ref-bar', status=NOTIFICATION_SENDING)
sent_letter = create_notification(sample_letter_template, reference='ref-foo', status=NOTIFICATION_SENDING,
billable_units=0)
failed_letter = create_notification(sample_letter_template, reference='ref-bar', status=NOTIFICATION_SENDING,
billable_units=0)
valid_file = '{}|Sent|1|Unsorted\n{}|Failed|2|Sorted'.format(
sent_letter.reference, failed_letter.reference)
@@ -106,7 +105,11 @@ def test_update_letter_notifications_statuses_persisted(notify_api, mocker, samp
update_letter_notifications_statuses(filename='foo.txt')
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.billable_units == 2
assert failed_letter.updated_at
def test_update_letter_notifications_to_sent_to_dvla_updates_based_on_notification_references(

View File

@@ -51,7 +51,7 @@ from app.dao.notifications_dao import (
set_scheduled_notification_to_processed,
update_notification_status_by_id,
update_notification_status_by_reference,
dao_get_last_notification_added_for_job_id)
dao_get_last_notification_added_for_job_id, dao_update_notifications_by_reference)
from app.dao.services_dao import dao_update_service
from tests.app.db import (
@@ -2065,3 +2065,38 @@ def test_dao_get_last_notification_added_for_job_id_no_notifications(sample_temp
def test_dao_get_last_notification_added_for_job_id_no_notifications(sample_template, fake_uuid):
assert dao_get_last_notification_added_for_job_id(fake_uuid) is None
def test_dao_update_notifications_by_reference_updated_notificaitons_and_history(sample_template):
notification_0 = create_notification(template=sample_template, reference='noref')
notification_1 = create_notification(template=sample_template, reference='ref')
notification_2 = create_notification(template=sample_template, reference='ref')
updated_count = dao_update_notifications_by_reference(references=['ref'],
update_dict={"status": "delivered",
"billable_units": 2}
)
assert updated_count == 2
updated_1 = Notification.query.get(notification_1.id)
assert updated_1.billable_units == 2
assert updated_1.status == 'delivered'
updated_2 = Notification.query.get(notification_2.id)
assert updated_2.billable_units == 2
assert updated_2.status == 'delivered'
updated_history_1 = NotificationHistory.query.get(notification_1.id)
assert updated_history_1.billable_units == 2
assert updated_history_1.status == 'delivered'
updated_history_2 = Notification.query.get(notification_2.id)
assert updated_history_2.billable_units == 2
assert updated_history_2.status == 'delivered'
assert notification_0 == Notification.query.get(notification_0.id)
def test_dao_update_notifications_by_reference_returns_zero_when_no_notifications_to_update(notify_db):
updated_count = dao_update_notifications_by_reference(references=['ref'],
update_dict={"status": "delivered",
"billable_units": 2}
)
assert updated_count == 0