Rename function for clarity

This commit is contained in:
Rebecca Law
2020-03-27 15:48:54 +00:00
parent 46b72a6bbb
commit 5d0830d7f7
5 changed files with 13 additions and 13 deletions

View File

@@ -39,7 +39,7 @@ def process_ses_results(self, response):
reference = ses_message['mail']['messageId'] reference = ses_message['mail']['messageId']
try: try:
notification = notifications_dao.dao_get_notification_history_by_reference(reference=reference) notification = notifications_dao.dao_get_notification_or_history_by_reference(reference=reference)
except NoResultFound: except NoResultFound:
message_time = iso8601.parse_date(ses_message['mail']['timestamp']).replace(tzinfo=None) message_time = iso8601.parse_date(ses_message['mail']['timestamp']).replace(tzinfo=None)
if datetime.utcnow() - message_time < timedelta(minutes=5): if datetime.utcnow() - message_time < timedelta(minutes=5):

View File

@@ -41,7 +41,7 @@ from app.dao.notifications_dao import (
dao_update_notifications_by_reference, dao_update_notifications_by_reference,
dao_get_last_notification_added_for_job_id, dao_get_last_notification_added_for_job_id,
update_notification_status_by_reference, update_notification_status_by_reference,
dao_get_notification_history_by_reference, dao_get_notification_or_history_by_reference,
) )
from app.dao.provider_details_dao import get_provider_details_by_notification_type from app.dao.provider_details_dao import get_provider_details_by_notification_type
from app.dao.returned_letters_dao import insert_or_update_returned_letters from app.dao.returned_letters_dao import insert_or_update_returned_letters
@@ -556,7 +556,7 @@ def update_letter_notification(filename, temporary_failures, update):
def check_billable_units(notification_update): def check_billable_units(notification_update):
notification = dao_get_notification_history_by_reference(notification_update.reference) notification = dao_get_notification_or_history_by_reference(notification_update.reference)
if int(notification_update.page_count) != notification.billable_units: if int(notification_update.page_count) != notification.billable_units:
msg = 'Notification with id {} has {} billable_units but DVLA says page count is {}'.format( msg = 'Notification with id {} has {} billable_units but DVLA says page count is {}'.format(

View File

@@ -631,7 +631,7 @@ def dao_get_notification_by_reference(reference):
@statsd(namespace="dao") @statsd(namespace="dao")
def dao_get_notification_history_by_reference(reference): def dao_get_notification_or_history_by_reference(reference):
try: try:
# This try except is necessary because in test keys and research mode does not create notification history. # This try except is necessary because in test keys and research mode does not create notification history.
# Otherwise we could just search for the NotificationHistory object # Otherwise we could just search for the NotificationHistory object

View File

@@ -1,7 +1,7 @@
from flask import current_app from flask import current_app
from app.dao.complaint_dao import save_complaint from app.dao.complaint_dao import save_complaint
from app.dao.notifications_dao import dao_get_notification_history_by_reference from app.dao.notifications_dao import dao_get_notification_or_history_by_reference
from app.dao.service_callback_api_dao import ( from app.dao.service_callback_api_dao import (
get_service_delivery_status_callback_api_for_service, get_service_complaint_callback_api_for_service get_service_delivery_status_callback_api_for_service, get_service_complaint_callback_api_for_service
) )
@@ -33,7 +33,7 @@ def handle_complaint(ses_message):
except KeyError as e: except KeyError as e:
current_app.logger.exception("Complaint from SES failed to get reference from message", e) current_app.logger.exception("Complaint from SES failed to get reference from message", e)
return return
notification = dao_get_notification_history_by_reference(reference) notification = dao_get_notification_or_history_by_reference(reference)
ses_complaint = ses_message.get('complaint', None) ses_complaint = ses_message.get('complaint', None)
complaint = Complaint( complaint = Complaint(

View File

@@ -31,7 +31,7 @@ from app.dao.notifications_dao import (
update_notification_status_by_reference, update_notification_status_by_reference,
dao_get_notification_by_reference, dao_get_notification_by_reference,
dao_get_notifications_by_references, dao_get_notifications_by_references,
dao_get_notification_history_by_reference, dao_get_notification_or_history_by_reference,
notifications_not_yet_sent, notifications_not_yet_sent,
) )
from app.models import ( from app.models import (
@@ -1620,28 +1620,28 @@ def test_dao_get_notifications_by_references(sample_template):
assert notifications[1].id in [notification_1.id, notification_2.id] assert notifications[1].id in [notification_1.id, notification_2.id]
def test_dao_get_notification_history_by_reference_with_one_match_returns_notification( def test_dao_get_notification_or_history_by_reference_with_one_match_returns_notification(
sample_letter_template sample_letter_template
): ):
create_notification(template=sample_letter_template, reference='REF1') create_notification(template=sample_letter_template, reference='REF1')
notification = dao_get_notification_history_by_reference('REF1') notification = dao_get_notification_or_history_by_reference('REF1')
assert notification.reference == 'REF1' assert notification.reference == 'REF1'
def test_dao_get_notification_history_by_reference_with_multiple_matches_raises_error( def test_dao_get_notification_or_history_by_reference_with_multiple_matches_raises_error(
sample_letter_template sample_letter_template
): ):
create_notification(template=sample_letter_template, reference='REF1') create_notification(template=sample_letter_template, reference='REF1')
create_notification(template=sample_letter_template, reference='REF1') create_notification(template=sample_letter_template, reference='REF1')
with pytest.raises(SQLAlchemyError): with pytest.raises(SQLAlchemyError):
dao_get_notification_history_by_reference('REF1') dao_get_notification_or_history_by_reference('REF1')
def test_dao_get_notification_history_by_reference_with_no_matches_raises_error(notify_db): def test_dao_get_notification_or_history_by_reference_with_no_matches_raises_error(notify_db):
with pytest.raises(SQLAlchemyError): with pytest.raises(SQLAlchemyError):
dao_get_notification_history_by_reference('REF1') dao_get_notification_or_history_by_reference('REF1')
@pytest.mark.parametrize("notification_type", @pytest.mark.parametrize("notification_type",