mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 07:12:20 -05:00
Prepare to stop inserting NotificationHistory at the time of inserting a notificaiton.
Need to remove foreign key to complaints. Make sure if getting Notification.id we look to both tables.
This commit is contained in:
@@ -18,7 +18,6 @@ from requests import (
|
||||
RequestException
|
||||
)
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import (
|
||||
create_uuid,
|
||||
@@ -42,7 +41,6 @@ from app.dao.notifications_dao import (
|
||||
dao_get_last_notification_added_for_job_id,
|
||||
update_notification_status_by_reference,
|
||||
dao_get_notification_history_by_reference,
|
||||
dao_get_notification_by_reference,
|
||||
)
|
||||
from app.dao.provider_details_dao import get_current_provider
|
||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||
@@ -498,12 +496,7 @@ def update_letter_notification(filename, temporary_failures, update):
|
||||
|
||||
|
||||
def check_billable_units(notification_update):
|
||||
try:
|
||||
# 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
|
||||
notification = dao_get_notification_by_reference(notification_update.reference)
|
||||
except NoResultFound:
|
||||
notification = dao_get_notification_history_by_reference(notification_update.reference)
|
||||
notification = dao_get_notification_history_by_reference(notification_update.reference)
|
||||
|
||||
if int(notification_update.page_count) != notification.billable_units:
|
||||
msg = 'Notification with id {} has {} billable_units but DVLA says page count is {}'.format(
|
||||
|
||||
@@ -17,6 +17,7 @@ from notifications_utils.statsd_decorators import statsd
|
||||
from notifications_utils.timezones import convert_utc_to_bst
|
||||
from sqlalchemy import (desc, func, asc)
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from sqlalchemy.sql import functions
|
||||
from sqlalchemy.sql.expression import case
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
@@ -585,9 +586,16 @@ def dao_get_notification_by_reference(reference):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_notification_history_by_reference(reference):
|
||||
return NotificationHistory.query.filter(
|
||||
NotificationHistory.reference == reference
|
||||
).one()
|
||||
try:
|
||||
# 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
|
||||
return Notification.query.filter(
|
||||
Notification.reference == reference
|
||||
).one()
|
||||
except NoResultFound:
|
||||
return NotificationHistory.query.filter(
|
||||
NotificationHistory.reference == reference
|
||||
).one()
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
|
||||
21
migrations/versions/0293_drop_complaint_fk.py
Normal file
21
migrations/versions/0293_drop_complaint_fk.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0293_drop_complaint_fk
|
||||
Revises: 0292_give_users_folder_perms
|
||||
Create Date: 2019-05-16 14:05:18.104274
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '0293_drop_complaint_fk'
|
||||
down_revision = '0292_give_users_folder_perms'
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.drop_constraint('complaints_notification_id_fkey', table_name='complaints', type_='foreignkey')
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.create_foreign_key('complaints_notification_id_fkey', 'complaints',
|
||||
'notification_history', ['notification_id'], ['id'])
|
||||
@@ -262,7 +262,7 @@ def test_toggle_sms_provider_switches_provider_stores_notify_user_id_in_history(
|
||||
assert old_provider_from_history.created_by_id == sample_user.id
|
||||
|
||||
|
||||
def test_can_get_all_provider_history(current_sms_provider):
|
||||
def test_can_get_all_provider_history(restore_provider_details, current_sms_provider):
|
||||
assert len(dao_get_provider_versions(current_sms_provider.id)) == 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user