From 2e7e6e81fcbae85f58b6c98ff1a100a0bf60fc47 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 9 Aug 2024 09:11:28 -0700 Subject: [PATCH 1/7] Need to remove priority logic --- app/config.py | 2 - app/dao/provider_details_dao.py | 22 +----- app/notifications/rest.py | 6 +- app/provider_details/rest.py | 1 - app/service/send_notification.py | 6 +- app/v2/notifications/post_notifications.py | 6 +- tests/app/dao/test_provider_details_dao.py | 71 ------------------- tests/app/provider_details/test_rest.py | 19 ----- .../test_send_notification.py | 43 ----------- .../test_send_one_off_notification.py | 18 ----- tests/app/test_config.py | 3 +- 11 files changed, 5 insertions(+), 192 deletions(-) diff --git a/app/config.py b/app/config.py index 65ef6b2d3..75cf0e783 100644 --- a/app/config.py +++ b/app/config.py @@ -11,7 +11,6 @@ from app.cloudfoundry_config import cloud_config class QueueNames(object): PERIODIC = "periodic-tasks" - PRIORITY = "priority-tasks" DATABASE = "database-tasks" SEND_SMS = "send-sms-tasks" CHECK_SMS = "check-sms_tasks" @@ -30,7 +29,6 @@ class QueueNames(object): @staticmethod def all_queues(): return [ - QueueNames.PRIORITY, QueueNames.PERIODIC, QueueNames.DATABASE, QueueNames.SEND_SMS, diff --git a/app/dao/provider_details_dao.py b/app/dao/provider_details_dao.py index 73132a44e..9b6b3b726 100644 --- a/app/dao/provider_details_dao.py +++ b/app/dao/provider_details_dao.py @@ -33,20 +33,6 @@ def dao_get_provider_versions(provider_id): ) -def _adjust_provider_priority(provider, new_priority): - current_app.logger.info( - f"Adjusting provider priority - {provider.identifier} going from {provider.priority} to {new_priority}" - ) - provider.priority = new_priority - - # Automatic update so set as notify user - provider.created_by_id = current_app.config["NOTIFY_USER_ID"] - - # update without commit so that both rows can be changed without ending the transaction - # and releasing the for_update lock - _update_provider_details_without_commit(provider) - - def _get_sms_providers_for_update(time_threshold): """ Returns a list of providers, while holding a for_update lock on the provider details table, guaranteeing that those @@ -86,11 +72,7 @@ def get_provider_details_by_notification_type( if supports_international: filters.append(ProviderDetails.supports_international == supports_international) - return ( - ProviderDetails.query.filter(*filters) - .order_by(asc(ProviderDetails.priority)) - .all() - ) + return ProviderDetails.query.filter(*filters).all() @autocommit @@ -135,7 +117,6 @@ def dao_get_provider_stats(): ProviderDetails.id, ProviderDetails.display_name, ProviderDetails.identifier, - ProviderDetails.priority, ProviderDetails.notification_type, ProviderDetails.active, ProviderDetails.updated_at, @@ -149,7 +130,6 @@ def dao_get_provider_stats(): .outerjoin(User, ProviderDetails.created_by_id == User.id) .order_by( ProviderDetails.notification_type, - ProviderDetails.priority, ) .all() ) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index f52bd1933..af1cd3ca4 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -168,11 +168,7 @@ def send_notification(notification_type): reply_to_text=template.reply_to_text, ) if not simulated: - queue_name = ( - QueueNames.PRIORITY - if template.process_type == TemplateProcessType.PRIORITY - else None - ) + queue_name = None send_notification_to_queue(notification=notification_model, queue=queue_name) else: diff --git a/app/provider_details/rest.py b/app/provider_details/rest.py index 9cc9f714a..3a7e62332 100644 --- a/app/provider_details/rest.py +++ b/app/provider_details/rest.py @@ -23,7 +23,6 @@ def get_providers(): "id": row.id, "display_name": row.display_name, "identifier": row.identifier, - "priority": row.priority, "notification_type": row.notification_type, "active": row.active, "updated_at": row.updated_at, diff --git a/app/service/send_notification.py b/app/service/send_notification.py index 4459ded3c..62628b1c4 100644 --- a/app/service/send_notification.py +++ b/app/service/send_notification.py @@ -80,11 +80,7 @@ def send_one_off_notification(service_id, post_data): client_reference=client_reference, ) - queue_name = ( - QueueNames.PRIORITY - if template.process_type == TemplateProcessType.PRIORITY - else None - ) + queue_name = None send_notification_to_queue( notification=notification, diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index 856179f85..eb1457d0a 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -176,11 +176,7 @@ def process_sms_or_email_notification( ) if not simulated: - queue_name = ( - QueueNames.PRIORITY - if template_process_type == TemplateProcessType.PRIORITY - else None - ) + queue_name = None send_notification_to_queue_detached( key_type=api_user.key_type, notification_type=notification_type, diff --git a/tests/app/dao/test_provider_details_dao.py b/tests/app/dao/test_provider_details_dao.py index b03d965d0..5a6f5c218 100644 --- a/tests/app/dao/test_provider_details_dao.py +++ b/tests/app/dao/test_provider_details_dao.py @@ -6,7 +6,6 @@ from sqlalchemy.sql import desc from app import notification_provider_clients from app.dao.provider_details_dao import ( - _adjust_provider_priority, _get_sms_providers_for_update, dao_get_provider_stats, dao_update_provider_details, @@ -33,9 +32,6 @@ def set_primary_sms_provider(identifier): get_alternative_sms_provider(identifier) ) - primary_provider.priority = 10 - secondary_provider.priority = 20 - dao_update_provider_details(primary_provider) dao_update_provider_details(secondary_provider) @@ -55,18 +51,6 @@ def test_can_get_sms_international_providers(notify_db_session): assert all(prov.supports_international for prov in sms_providers) -def test_can_get_sms_providers_in_order_of_priority(notify_db_session): - providers = get_provider_details_by_notification_type(NotificationType.SMS, False) - priorities = [provider.priority for provider in providers] - assert priorities == sorted(priorities) - - -def test_can_get_email_providers_in_order_of_priority(notify_db_session): - providers = get_provider_details_by_notification_type(NotificationType.EMAIL) - - assert providers[0].identifier == "ses" - - def test_can_get_email_providers(notify_db_session): assert len(get_provider_details_by_notification_type(NotificationType.EMAIL)) == 1 types = [ @@ -146,61 +130,6 @@ def test_get_alternative_sms_provider_fails_if_unrecognised(): get_alternative_sms_provider("ses") -@freeze_time("2016-01-01 00:30") -def test_adjust_provider_priority_sets_priority( - restore_provider_details, - notify_user, - sns_provider, -): - # need to update these manually to avoid triggering the `onupdate` clause of the updated_at column - ProviderDetails.query.filter(ProviderDetails.identifier == "sns").update( - {"updated_at": datetime.min} - ) - - _adjust_provider_priority(sns_provider, 50) - - assert sns_provider.updated_at == utc_now() - assert sns_provider.created_by.id == notify_user.id - assert sns_provider.priority == 50 - - -@freeze_time("2016-01-01 00:30") -def test_adjust_provider_priority_adds_history( - restore_provider_details, - notify_user, - sns_provider, -): - # need to update these manually to avoid triggering the `onupdate` clause of the updated_at column - ProviderDetails.query.filter(ProviderDetails.identifier == "sns").update( - {"updated_at": datetime.min} - ) - - old_provider_history_rows = ( - ProviderDetailsHistory.query.filter( - ProviderDetailsHistory.id == sns_provider.id - ) - .order_by(desc(ProviderDetailsHistory.version)) - .all() - ) - - _adjust_provider_priority(sns_provider, 50) - - updated_provider_history_rows = ( - ProviderDetailsHistory.query.filter( - ProviderDetailsHistory.id == sns_provider.id - ) - .order_by(desc(ProviderDetailsHistory.version)) - .all() - ) - - assert len(updated_provider_history_rows) - len(old_provider_history_rows) == 1 - assert ( - updated_provider_history_rows[0].version - old_provider_history_rows[0].version - == 1 - ) - assert updated_provider_history_rows[0].priority == 50 - - @freeze_time("2016-01-01 01:00") def test_get_sms_providers_for_update_returns_providers(restore_provider_details): ProviderDetails.query.filter(ProviderDetails.identifier == "sns").update( diff --git a/tests/app/provider_details/test_rest.py b/tests/app/provider_details/test_rest.py index b0f67a5b6..5deb88bd8 100644 --- a/tests/app/provider_details/test_rest.py +++ b/tests/app/provider_details/test_rest.py @@ -42,7 +42,6 @@ def test_get_provider_contains_correct_fields(client, sample_template): "created_by_name", "display_name", "identifier", - "priority", "notification_type", "active", "updated_at", @@ -53,24 +52,6 @@ def test_get_provider_contains_correct_fields(client, sample_template): assert allowed_keys == set(json_resp[0].keys()) -def test_should_be_able_to_update_priority(client, restore_provider_details): - provider = ProviderDetails.query.first() - - update_resp = client.post( - "/provider-details/{}".format(provider.id), - headers=[ - ("Content-Type", "application/json"), - create_admin_authorization_header(), - ], - data=json.dumps({"priority": 5}), - ) - assert update_resp.status_code == 200 - update_json = json.loads(update_resp.get_data(as_text=True))["provider_details"] - assert update_json["identifier"] == provider.identifier - assert update_json["priority"] == 5 - assert provider.priority == 5 - - def test_should_be_able_to_update_status(client, restore_provider_details): provider = ProviderDetails.query.first() diff --git a/tests/app/service/send_notification/test_send_notification.py b/tests/app/service/send_notification/test_send_notification.py index 036c5bac8..464077bf0 100644 --- a/tests/app/service/send_notification/test_send_notification.py +++ b/tests/app/service/send_notification/test_send_notification.py @@ -1113,49 +1113,6 @@ def test_create_template_raises_invalid_request_when_content_too_large( } -@pytest.mark.parametrize( - "notification_type,send_to", - [ - (NotificationType.SMS, "2028675309"), - ( - NotificationType.EMAIL, - "sample@email.com", - ), - ], -) -def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority( - client, - sample_service, - mocker, - notification_type, - send_to, -): - sample = create_template( - sample_service, - template_type=notification_type, - process_type=TemplateProcessType.PRIORITY, - ) - mocked = mocker.patch( - f"app.celery.provider_tasks.deliver_{notification_type}.apply_async" - ) - - data = {"to": send_to, "template": str(sample.id)} - - auth_header = create_service_authorization_header(service_id=sample.service_id) - - response = client.post( - path=f"/notifications/{notification_type}", - data=json.dumps(data), - headers=[("Content-Type", "application/json"), auth_header], - ) - - response_data = json.loads(response.data)["data"] - notification_id = response_data["notification"]["id"] - - assert response.status_code == 201 - mocked.assert_called_once_with([notification_id], queue="priority-tasks") - - @pytest.mark.parametrize( "notification_type, send_to", [ diff --git a/tests/app/service/send_notification/test_send_one_off_notification.py b/tests/app/service/send_notification/test_send_one_off_notification.py index 9983515c7..889a3e0c1 100644 --- a/tests/app/service/send_notification/test_send_one_off_notification.py +++ b/tests/app/service/send_notification/test_send_one_off_notification.py @@ -161,24 +161,6 @@ def test_send_one_off_notification_calls_persist_correctly_for_email( ) -def test_send_one_off_notification_honors_priority( - notify_db_session, persist_mock, celery_mock -): - service = create_service() - template = create_template(service=service) - template.process_type = TemplateProcessType.PRIORITY - - post_data = { - "template_id": str(template.id), - "to": "202-867-5309", - "created_by": str(service.created_by_id), - } - - send_one_off_notification(service.id, post_data) - - assert celery_mock.call_args[1]["queue"] == QueueNames.PRIORITY - - def test_send_one_off_notification_raises_if_invalid_recipient(notify_db_session): service = create_service() template = create_template(service=service) diff --git a/tests/app/test_config.py b/tests/app/test_config.py index 2d9591be8..46a061ddd 100644 --- a/tests/app/test_config.py +++ b/tests/app/test_config.py @@ -4,10 +4,9 @@ from app.config import QueueNames def test_queue_names_all_queues_correct(): # Need to ensure that all_queues() only returns queue names used in API queues = QueueNames.all_queues() - assert len(queues) == 15 + assert len(queues) == 14 assert set( [ - QueueNames.PRIORITY, QueueNames.PERIODIC, QueueNames.DATABASE, QueueNames.SEND_SMS, From 8444b7669094ab9d4528eb63bdcb03312403dd3a Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 9 Aug 2024 09:18:58 -0700 Subject: [PATCH 2/7] fix flake8 --- app/dao/provider_details_dao.py | 2 +- app/notifications/rest.py | 3 +-- app/service/send_notification.py | 3 +-- app/v2/notifications/post_notifications.py | 2 +- tests/app/dao/test_provider_details_dao.py | 2 -- tests/app/service/send_notification/test_send_notification.py | 2 +- .../send_notification/test_send_one_off_notification.py | 2 -- 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/dao/provider_details_dao.py b/app/dao/provider_details_dao.py index 9b6b3b726..b0ab48d09 100644 --- a/app/dao/provider_details_dao.py +++ b/app/dao/provider_details_dao.py @@ -1,7 +1,7 @@ from datetime import datetime from flask import current_app -from sqlalchemy import asc, desc, func +from sqlalchemy import desc, func from app import db from app.dao.dao_utils import autocommit diff --git a/app/notifications/rest.py b/app/notifications/rest.py index af1cd3ca4..43224f0e7 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -2,9 +2,8 @@ from flask import Blueprint, current_app, jsonify, request from app import api_user, authenticated_service from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3 -from app.config import QueueNames from app.dao import notifications_dao -from app.enums import KeyType, NotificationType, TemplateProcessType +from app.enums import KeyType, NotificationType from app.errors import InvalidRequest, register_errors from app.notifications.process_notifications import ( persist_notification, diff --git a/app/service/send_notification.py b/app/service/send_notification.py index 62628b1c4..6e29c0e59 100644 --- a/app/service/send_notification.py +++ b/app/service/send_notification.py @@ -1,12 +1,11 @@ from sqlalchemy.orm.exc import NoResultFound -from app.config import QueueNames from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id from app.dao.services_dao import dao_fetch_service_by_id from app.dao.templates_dao import dao_get_template_by_id_and_service_id from app.dao.users_dao import get_user_by_id -from app.enums import KeyType, NotificationType, TemplateProcessType +from app.enums import KeyType, NotificationType from app.errors import BadRequestError from app.notifications.process_notifications import ( persist_notification, diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index eb1457d0a..b006b57f5 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -8,7 +8,7 @@ from app import api_user, authenticated_service, document_download_client, encry from app.celery.tasks import save_api_email, save_api_sms from app.clients.document_download import DocumentDownloadError from app.config import QueueNames -from app.enums import KeyType, NotificationStatus, NotificationType, TemplateProcessType +from app.enums import KeyType, NotificationStatus, NotificationType from app.models import Notification from app.notifications.process_notifications import ( persist_notification, diff --git a/tests/app/dao/test_provider_details_dao.py b/tests/app/dao/test_provider_details_dao.py index 5a6f5c218..fd8f4a43d 100644 --- a/tests/app/dao/test_provider_details_dao.py +++ b/tests/app/dao/test_provider_details_dao.py @@ -2,7 +2,6 @@ from datetime import datetime, timedelta import pytest from freezegun import freeze_time -from sqlalchemy.sql import desc from app import notification_provider_clients from app.dao.provider_details_dao import ( @@ -15,7 +14,6 @@ from app.dao.provider_details_dao import ( ) from app.enums import NotificationType, TemplateType from app.models import ProviderDetails, ProviderDetailsHistory -from app.utils import utc_now from tests.app.db import create_ft_billing, create_service, create_template from tests.conftest import set_config diff --git a/tests/app/service/send_notification/test_send_notification.py b/tests/app/service/send_notification/test_send_notification.py index 464077bf0..dcd6cc8e7 100644 --- a/tests/app/service/send_notification/test_send_notification.py +++ b/tests/app/service/send_notification/test_send_notification.py @@ -11,7 +11,7 @@ from app.dao import notifications_dao from app.dao.api_key_dao import save_model_api_key from app.dao.services_dao import dao_update_service from app.dao.templates_dao import dao_get_all_templates_for_service, dao_update_template -from app.enums import KeyType, NotificationType, TemplateProcessType, TemplateType +from app.enums import KeyType, NotificationType, TemplateType from app.errors import InvalidRequest, RateLimitError from app.models import ApiKey, Notification, NotificationHistory, Template from app.service.send_notification import send_one_off_notification diff --git a/tests/app/service/send_notification/test_send_one_off_notification.py b/tests/app/service/send_notification/test_send_one_off_notification.py index 889a3e0c1..78ab0977e 100644 --- a/tests/app/service/send_notification/test_send_one_off_notification.py +++ b/tests/app/service/send_notification/test_send_one_off_notification.py @@ -3,14 +3,12 @@ from unittest.mock import Mock import pytest -from app.config import QueueNames from app.dao.service_guest_list_dao import dao_add_and_commit_guest_list_contacts from app.enums import ( KeyType, NotificationType, RecipientType, ServicePermissionType, - TemplateProcessType, TemplateType, ) from app.errors import BadRequestError From 36e5614d4a53fceeb41632d0c92a46caa6f467e8 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 9 Aug 2024 09:28:50 -0700 Subject: [PATCH 3/7] fix flake8 --- app/v2/notifications/post_notifications.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index b006b57f5..a5ad17646 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -85,7 +85,6 @@ def process_sms_or_email_notification( notification_type, template, template_with_content, - template_process_type, service, reply_to_text=None, ): From be6e9eb40f1d4ca3fee0f48f57fddda860954525 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 12 Aug 2024 12:52:06 -0700 Subject: [PATCH 4/7] remove priority column --- migrations/versions/0412_remove_priority.py | 22 +++++++++++++++++++++ poetry.lock | 5 +---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/0412_remove_priority.py diff --git a/migrations/versions/0412_remove_priority.py b/migrations/versions/0412_remove_priority.py new file mode 100644 index 000000000..8367e541a --- /dev/null +++ b/migrations/versions/0412_remove_priority.py @@ -0,0 +1,22 @@ +""" + +Revision ID: 0412_remove_priority +Revises: 411_add_login_uuid + +""" + +import sqlalchemy as sa +from alembic import op + +revision = "0412_remove_priority" +down_revision = "0411_add_login_uuid" + + +def upgrade(): + op.drop_column("provider_details", sa.Column("priority")) + op.drop_column("provider_details_history", sa.Column("priority")) + + +def downgrade(): + op.add_column("provider_details", sa.Column("priority", sa.Integer())) + op.add_column("provider_details_history", sa.Column("priority", sa.Integer())) diff --git a/poetry.lock b/poetry.lock index f7f337f51..eabbfc4e6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2093,13 +2093,9 @@ files = [ {file = "lxml-5.2.2-cp36-cp36m-win_amd64.whl", hash = "sha256:edcfa83e03370032a489430215c1e7783128808fd3e2e0a3225deee278585196"}, {file = "lxml-5.2.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:28bf95177400066596cdbcfc933312493799382879da504633d16cf60bba735b"}, {file = "lxml-5.2.2-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3a745cc98d504d5bd2c19b10c79c61c7c3df9222629f1b6210c0368177589fb8"}, - {file = "lxml-5.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1b590b39ef90c6b22ec0be925b211298e810b4856909c8ca60d27ffbca6c12e6"}, {file = "lxml-5.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b336b0416828022bfd5a2e3083e7f5ba54b96242159f83c7e3eebaec752f1716"}, - {file = "lxml-5.2.2-cp37-cp37m-manylinux_2_28_aarch64.whl", hash = "sha256:c2faf60c583af0d135e853c86ac2735ce178f0e338a3c7f9ae8f622fd2eb788c"}, {file = "lxml-5.2.2-cp37-cp37m-manylinux_2_28_x86_64.whl", hash = "sha256:4bc6cb140a7a0ad1f7bc37e018d0ed690b7b6520ade518285dc3171f7a117905"}, - {file = "lxml-5.2.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:7ff762670cada8e05b32bf1e4dc50b140790909caa8303cfddc4d702b71ea184"}, {file = "lxml-5.2.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:57f0a0bbc9868e10ebe874e9f129d2917750adf008fe7b9c1598c0fbbfdde6a6"}, - {file = "lxml-5.2.2-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:a6d2092797b388342c1bc932077ad232f914351932353e2e8706851c870bca1f"}, {file = "lxml-5.2.2-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:60499fe961b21264e17a471ec296dcbf4365fbea611bf9e303ab69db7159ce61"}, {file = "lxml-5.2.2-cp37-cp37m-win32.whl", hash = "sha256:d9b342c76003c6b9336a80efcc766748a333573abf9350f4094ee46b006ec18f"}, {file = "lxml-5.2.2-cp37-cp37m-win_amd64.whl", hash = "sha256:b16db2770517b8799c79aa80f4053cd6f8b716f21f8aca962725a9565ce3ee40"}, @@ -2488,6 +2484,7 @@ files = [ {file = "msgpack-1.0.8-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5fbb160554e319f7b22ecf530a80a3ff496d38e8e07ae763b9e82fadfe96f273"}, {file = "msgpack-1.0.8-cp39-cp39-win32.whl", hash = "sha256:f9af38a89b6a5c04b7d18c492c8ccf2aee7048aff1ce8437c4683bb5a1df893d"}, {file = "msgpack-1.0.8-cp39-cp39-win_amd64.whl", hash = "sha256:ed59dd52075f8fc91da6053b12e8c89e37aa043f8986efd89e61fae69dc1b011"}, + {file = "msgpack-1.0.8-py3-none-any.whl", hash = "sha256:24f727df1e20b9876fa6e95f840a2a2651e34c0ad147676356f4bf5fbb0206ca"}, {file = "msgpack-1.0.8.tar.gz", hash = "sha256:95c02b0e27e706e48d0e5426d1710ca78e0f0628d6e89d5b5a5b91a5f12274f3"}, ] From 99d687da4f092c6f3a1d44440e43f8e50cee92a2 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 12 Aug 2024 13:09:13 -0700 Subject: [PATCH 5/7] add migration --- migrations/versions/0412_remove_priority.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migrations/versions/0412_remove_priority.py b/migrations/versions/0412_remove_priority.py index 8367e541a..55e40260a 100644 --- a/migrations/versions/0412_remove_priority.py +++ b/migrations/versions/0412_remove_priority.py @@ -13,10 +13,12 @@ down_revision = "0411_add_login_uuid" def upgrade(): + print("DELETING COLUMNS") op.drop_column("provider_details", sa.Column("priority")) op.drop_column("provider_details_history", sa.Column("priority")) def downgrade(): + print("ADDING COLUMNS") op.add_column("provider_details", sa.Column("priority", sa.Integer())) op.add_column("provider_details_history", sa.Column("priority", sa.Integer())) From 486d5f66e95bd29b9dde277d70ed5908dfcae5b5 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 12 Aug 2024 14:07:26 -0700 Subject: [PATCH 6/7] fix tests --- app/models.py | 2 -- migrations/versions/0412_remove_priority.py | 8 ++++---- tests/app/provider_details/test_rest.py | 1 - tests/conftest.py | 8 ++------ 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/models.py b/app/models.py index 0d58a6611..c37f5a96b 100644 --- a/app/models.py +++ b/app/models.py @@ -1297,7 +1297,6 @@ class ProviderDetails(db.Model): id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) display_name = db.Column(db.String, nullable=False) identifier = db.Column(db.String, nullable=False) - priority = db.Column(db.Integer, nullable=False) notification_type = enum_column(NotificationType, nullable=False) active = db.Column(db.Boolean, default=False, nullable=False) version = db.Column(db.Integer, default=1, nullable=False) @@ -1322,7 +1321,6 @@ class ProviderDetailsHistory(db.Model, HistoryModel): id = db.Column(UUID(as_uuid=True), primary_key=True, nullable=False) display_name = db.Column(db.String, nullable=False) identifier = db.Column(db.String, nullable=False) - priority = db.Column(db.Integer, nullable=False) notification_type = enum_column(NotificationType, nullable=False) active = db.Column(db.Boolean, nullable=False) version = db.Column(db.Integer, primary_key=True, nullable=False) diff --git a/migrations/versions/0412_remove_priority.py b/migrations/versions/0412_remove_priority.py index 55e40260a..032e4ddd9 100644 --- a/migrations/versions/0412_remove_priority.py +++ b/migrations/versions/0412_remove_priority.py @@ -14,11 +14,11 @@ down_revision = "0411_add_login_uuid" def upgrade(): print("DELETING COLUMNS") - op.drop_column("provider_details", sa.Column("priority")) - op.drop_column("provider_details_history", sa.Column("priority")) + op.drop_column("provider_details", "priority") + op.drop_column("provider_details_history", "priority") def downgrade(): print("ADDING COLUMNS") - op.add_column("provider_details", sa.Column("priority", sa.Integer())) - op.add_column("provider_details_history", sa.Column("priority", sa.Integer())) + op.add_column("provider_details", sa.Column("priority", sa.Integer)) + op.add_column("provider_details_history", sa.Column("priority", sa.Integer)) diff --git a/tests/app/provider_details/test_rest.py b/tests/app/provider_details/test_rest.py index 5deb88bd8..a5780fcb6 100644 --- a/tests/app/provider_details/test_rest.py +++ b/tests/app/provider_details/test_rest.py @@ -105,7 +105,6 @@ def test_get_provider_versions_contains_correct_fields(client, notify_db_session "created_by", "display_name", "identifier", - "priority", "notification_type", "active", "version", diff --git a/tests/conftest.py b/tests/conftest.py index 2a4c53113..2237d8fc6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -80,12 +80,8 @@ def _notify_db(notify_api): @pytest.fixture(scope="function") def sms_providers(_notify_db): - """ - In production we randomly choose which provider to use based on their priority. To guarantee tests run the same each - time, make sure we always choose sns. You'll need to override them in your tests if you wish to do something - different. - """ - get_provider_details_by_identifier("sns").priority = 100 + pass + # get_provider_details_by_identifier("sns").priority = 100 @pytest.fixture(scope="function") From 6138c827ad4cf85895834481fc75b5473b1bcaca Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 12 Aug 2024 14:17:11 -0700 Subject: [PATCH 7/7] fix flake8 --- tests/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2237d8fc6..7ce2c8033 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,6 @@ from flask import Flask from sqlalchemy_utils import create_database, database_exists, drop_database from app import create_app -from app.dao.provider_details_dao import get_provider_details_by_identifier @pytest.fixture(scope="session")