From 1f0a64d6a57bee3098e6e77a3cc452618c9ba526 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Fri, 15 Nov 2024 12:30:58 -0800 Subject: [PATCH] more --- .../test_send_one_off_notification.py | 7 ++++--- tests/app/service/test_service_guest_list.py | 12 ++++++++++-- tests/app/service/test_suspend_resume_service.py | 6 +++++- tests/app/service_invite/test_service_invite_rest.py | 4 +++- tests/app/template/test_rest.py | 9 +++++---- .../app/template_folder/test_template_folder_rest.py | 2 +- tests/app/test_model.py | 5 +++-- 7 files changed, 31 insertions(+), 14 deletions(-) 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 78ab0977e..92d329b06 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,6 +3,7 @@ from unittest.mock import Mock import pytest +from app import db from app.dao.service_guest_list_dao import dao_add_and_commit_guest_list_contacts from app.enums import ( KeyType, @@ -266,7 +267,7 @@ def test_send_one_off_notification_should_add_email_reply_to_text_for_notificati notification_id = send_one_off_notification( service_id=sample_email_template.service.id, post_data=data ) - notification = Notification.query.get(notification_id["id"]) + notification = db.session.get(Notification, notification_id["id"]) celery_mock.assert_called_once_with(notification=notification, queue=None) assert notification.reply_to_text == reply_to_email.email_address @@ -289,7 +290,7 @@ def test_send_one_off_sms_notification_should_use_sms_sender_reply_to_text( notification_id = send_one_off_notification( service_id=sample_service.id, post_data=data ) - notification = Notification.query.get(notification_id["id"]) + notification = db.session.get(Notification, notification_id["id"]) celery_mock.assert_called_once_with(notification=notification, queue=None) assert notification.reply_to_text == "+12028675309" @@ -313,7 +314,7 @@ def test_send_one_off_sms_notification_should_use_default_service_reply_to_text( notification_id = send_one_off_notification( service_id=sample_service.id, post_data=data ) - notification = Notification.query.get(notification_id["id"]) + notification = db.session.get(Notification, notification_id["id"]) celery_mock.assert_called_once_with(notification=notification, queue=None) assert notification.reply_to_text == "+12028675309" diff --git a/tests/app/service/test_service_guest_list.py b/tests/app/service/test_service_guest_list.py index 5d86a06c2..40e0c4d24 100644 --- a/tests/app/service/test_service_guest_list.py +++ b/tests/app/service/test_service_guest_list.py @@ -1,6 +1,9 @@ import json import uuid +from sqlalchemy import select + +from app import db from app.dao.service_guest_list_dao import dao_add_and_commit_guest_list_contacts from app.enums import RecipientType from app.models import ServiceGuestList @@ -87,7 +90,12 @@ def test_update_guest_list_replaces_old_guest_list(client, sample_service_guest_ ) assert response.status_code == 204 - guest_list = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all() + guest_list = ( + db.session.execute(select(ServiceGuestList)) + .order_by(ServiceGuestList.recipient) + .scalars() + .all() + ) assert len(guest_list) == 2 assert guest_list[0].recipient == "+12028765309" assert guest_list[1].recipient == "foo@bar.com" @@ -112,5 +120,5 @@ def test_update_guest_list_doesnt_remove_old_guest_list_if_error( "result": "error", "message": 'Invalid guest list: "" is not a valid email address or phone number', } - guest_list = ServiceGuestList.query.one() + guest_list = db.session.execute(select(ServiceGuestList)).scalars().one() assert guest_list.id == sample_service_guest_list.id diff --git a/tests/app/service/test_suspend_resume_service.py b/tests/app/service/test_suspend_resume_service.py index a5b87f6fb..2c2d41837 100644 --- a/tests/app/service/test_suspend_resume_service.py +++ b/tests/app/service/test_suspend_resume_service.py @@ -3,7 +3,9 @@ from datetime import datetime import pytest from freezegun import freeze_time +from sqlalchemy import select +from app import db from app.models import Service from tests import create_admin_authorization_header @@ -77,8 +79,10 @@ def test_service_history_is_created(client, sample_service, action, original_sta ) ServiceHistory = Service.get_history_model() history = ( - ServiceHistory.query.filter_by(id=sample_service.id) + db.session.execute(select(ServiceHistory)) + .filter_by(id=sample_service.id) .order_by(ServiceHistory.version.desc()) + .scalars() .first() ) diff --git a/tests/app/service_invite/test_service_invite_rest.py b/tests/app/service_invite/test_service_invite_rest.py index 61b8b79e7..a3cdf681e 100644 --- a/tests/app/service_invite/test_service_invite_rest.py +++ b/tests/app/service_invite/test_service_invite_rest.py @@ -5,7 +5,9 @@ from functools import partial import pytest from flask import current_app from freezegun import freeze_time +from sqlalchemy import select +from app import db from app.enums import AuthType, InvitedUserStatus from app.models import Notification from notifications_utils.url_safe_token import generate_token @@ -72,7 +74,7 @@ def test_create_invited_user( "folder_3", ] - notification = Notification.query.first() + notification = db.session.execute(select(Notification)).scalars().first() assert notification.reply_to_text == invite_from.email_address diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index d46627343..349230696 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -60,7 +60,7 @@ def test_should_create_a_new_template_for_a_service( else: assert not json_resp["data"]["subject"] - template = Template.query.get(json_resp["data"]["id"]) + template = db.session.get(Template, json_resp["data"]["id"]) from app.schemas import template_schema assert sorted(json_resp["data"]) == sorted(template_schema.dump(template)) @@ -352,7 +352,8 @@ def test_update_should_update_a_template(client, sample_user): assert update_json_resp["data"]["created_by"] == str(sample_user.id) template_created_by_users = [ - template.created_by_id for template in TemplateHistory.query.all() + template.created_by_id + for template in db.session.execute(select(TemplateHistory)).scalars().all() ] assert len(template_created_by_users) == 2 assert service.created_by.id in template_created_by_users @@ -380,7 +381,7 @@ def test_should_be_able_to_archive_template(client, sample_template): ) assert resp.status_code == 200 - assert Template.query.first().archived + assert db.session.execute(select(Template)).scalars().first().archived def test_should_be_able_to_archive_template_should_remove_template_folders( @@ -402,7 +403,7 @@ def test_should_be_able_to_archive_template_should_remove_template_folders( data=json.dumps(data), ) - updated_template = Template.query.get(template.id) + updated_template = db.session.get(Template, template.id) assert updated_template.archived assert not updated_template.folder diff --git a/tests/app/template_folder/test_template_folder_rest.py b/tests/app/template_folder/test_template_folder_rest.py index 3bd2b4ee9..64a232192 100644 --- a/tests/app/template_folder/test_template_folder_rest.py +++ b/tests/app/template_folder/test_template_folder_rest.py @@ -270,7 +270,7 @@ def test_delete_template_folder(admin_request, sample_service): template_folder_id=existing_folder.id, ) - assert TemplateFolder.query.all() == [] + assert db.session.execute(select(TemplateFolder)).scalars().all() == [] def test_delete_template_folder_fails_if_folder_has_subfolders( diff --git a/tests/app/test_model.py b/tests/app/test_model.py index e74ef06ff..4b6dec10c 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -1,8 +1,9 @@ import pytest from freezegun import freeze_time +from sqlalchemy import select from sqlalchemy.exc import IntegrityError -from app import encryption +from app import db, encryption from app.enums import ( AgreementStatus, AgreementType, @@ -408,7 +409,7 @@ def test_annual_billing_serialize(): def test_repr(): service = create_service() - sps = ServicePermission.query.all() + sps = db.session.execute(select(ServicePermission)).scalars().all() for sp in sps: assert "has service permission" in sp.__repr__()