mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Use dao_update_notification to update billable_units for letter notifications
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from datetime import datetime
|
||||
from flask import current_app
|
||||
import math
|
||||
from requests import (
|
||||
@@ -14,7 +13,7 @@ from app.config import QueueNames
|
||||
from app.dao.notifications_dao import (
|
||||
get_notification_by_id,
|
||||
update_notification_status_by_id,
|
||||
dao_update_notifications_by_reference
|
||||
dao_update_notification
|
||||
)
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
@@ -35,22 +34,12 @@ def create_letters_pdf(self, notification_id):
|
||||
notification.id, notification.reference, notification.created_at, len(pdf_data)))
|
||||
s3.upload_letters_pdf(reference=notification.reference, crown=notification.service.crown, filedata=pdf_data)
|
||||
|
||||
updated_count = dao_update_notifications_by_reference(
|
||||
references=[notification.reference],
|
||||
update_dict={
|
||||
"billable_units": billable_units,
|
||||
"updated_at": datetime.utcnow()
|
||||
}
|
||||
)
|
||||
notification.billable_units = billable_units
|
||||
dao_update_notification(notification)
|
||||
|
||||
if not updated_count:
|
||||
msg = "Update letter notification billing units failed: notification not found with reference {}".format(
|
||||
notification.reference)
|
||||
current_app.logger.error(msg)
|
||||
else:
|
||||
current_app.logger.info(
|
||||
'Letter notification reference {reference}: billable units set to {billable_units}'.format(
|
||||
reference=str(notification.reference), billable_units=billable_units))
|
||||
current_app.logger.info(
|
||||
'Letter notification reference {reference}: billable units set to {billable_units}'.format(
|
||||
reference=str(notification.reference), billable_units=billable_units))
|
||||
|
||||
except (RequestException, BotoClientError):
|
||||
try:
|
||||
|
||||
@@ -97,19 +97,6 @@ def test_create_letters_pdf_sets_billable_units(mocker, sample_letter_notificati
|
||||
assert noti.billable_units == 1
|
||||
|
||||
|
||||
def test_create_letters_pdf_handles_update_failure(mocker, sample_letter_notification):
|
||||
mocker.patch('app.celery.letters_pdf_tasks.get_letters_pdf', return_value=(b'\x00\x01', 1))
|
||||
mocker.patch('app.celery.tasks.s3.upload_letters_pdf')
|
||||
mocker.patch('app.celery.tasks.letters_pdf_tasks.dao_update_notifications_by_reference', return_value=0)
|
||||
mock_error_logger = mocker.patch('app.celery.letters_pdf_tasks.current_app.logger.error')
|
||||
|
||||
create_letters_pdf(sample_letter_notification.id)
|
||||
|
||||
mock_error_logger.assert_called_once_with(
|
||||
"Update letter notification billing units failed: notification not found with reference {}".format(
|
||||
sample_letter_notification.reference))
|
||||
|
||||
|
||||
def test_create_letters_pdf_non_existent_notification(notify_api, mocker, fake_uuid):
|
||||
with pytest.raises(expected_exception=NoResultFound):
|
||||
create_letters_pdf(fake_uuid)
|
||||
|
||||
Reference in New Issue
Block a user