mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-20 00:30:41 -04:00
Merge branch 'master' into add-delivery-receipts-app
This commit is contained in:
@@ -33,20 +33,19 @@ from app.dao.jobs_dao import (
|
||||
dao_get_job_by_id,
|
||||
all_notifications_are_created_for_job,
|
||||
dao_get_all_notifications_for_job,
|
||||
dao_update_job_status)
|
||||
dao_update_job_status
|
||||
)
|
||||
from app.dao.notifications_dao import (
|
||||
get_notification_by_id,
|
||||
update_notification_status_by_reference,
|
||||
dao_update_notifications_for_job_to_sent_to_dvla,
|
||||
dao_update_notifications_by_reference,
|
||||
dao_get_last_notification_added_for_job_id)
|
||||
dao_get_last_notification_added_for_job_id
|
||||
)
|
||||
from app.dao.provider_details_dao import get_current_provider
|
||||
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
|
||||
from app.dao.services_dao import dao_fetch_service_by_id, fetch_todays_total_message_count
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import (
|
||||
Job,
|
||||
Notification,
|
||||
DVLA_RESPONSE_STATUS_SENT,
|
||||
EMAIL_TYPE,
|
||||
JOB_STATUS_CANCELLED,
|
||||
@@ -449,9 +448,12 @@ def update_letter_notifications_statuses(self, filename):
|
||||
for update in notification_updates:
|
||||
status = NOTIFICATION_DELIVERED if update.status == DVLA_RESPONSE_STATUS_SENT \
|
||||
else NOTIFICATION_TECHNICAL_FAILURE
|
||||
notification = update_notification_status_by_reference(
|
||||
update.reference,
|
||||
status
|
||||
notification = dao_update_notifications_by_reference(
|
||||
references=[update.reference],
|
||||
update_dict={"status": status,
|
||||
"billable_units": update.page_count,
|
||||
"updated_at": datetime.utcnow()
|
||||
}
|
||||
)
|
||||
|
||||
if not notification:
|
||||
|
||||
@@ -493,7 +493,6 @@ def dao_update_notifications_for_job_to_sent_to_dvla(job_id, provider):
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def dao_update_notifications_by_reference(references, update_dict):
|
||||
now = datetime.utcnow()
|
||||
updated_count = Notification.query.filter(
|
||||
Notification.reference.in_(references)
|
||||
).update(
|
||||
|
||||
33
migrations/versions/0130_service_email_reply_to_row.py
Normal file
33
migrations/versions/0130_service_email_reply_to_row.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0130_service_email_reply_to_row
|
||||
Revises: 0129_add_email_auth_permission
|
||||
Create Date: 2017-08-29 14:09:41.042061
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0130_service_email_reply_to_row'
|
||||
down_revision = '0129_add_email_auth_permission'
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553'
|
||||
EMAIL_REPLY_TO_ID = 'b3a58d57-2337-662a-4cba-40792a9322f2'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute("""
|
||||
INSERT INTO service_email_reply_to
|
||||
(id, service_id, email_address, is_default, created_at)
|
||||
VALUES
|
||||
('{}','{}', 'notify+1@digital.cabinet-office.gov.uk', 'f', NOW())
|
||||
""".format(EMAIL_REPLY_TO_ID, NOTIFY_SERVICE_ID))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute("""
|
||||
DELETE FROM service_email_reply_to
|
||||
WHERE id = '{}'
|
||||
""".format(EMAIL_REPLY_TO_ID))
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user