Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Nov 15, 2024
1 parent 703a29f commit 1f0a64d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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,
Expand Down Expand Up @@ -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

Expand All @@ -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"
Expand All @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions tests/app/service/test_service_guest_list.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 == "[email protected]"
Expand All @@ -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
6 changes: 5 additions & 1 deletion tests/app/service/test_suspend_resume_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

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

Expand Down Expand Up @@ -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()
)

Expand Down
4 changes: 3 additions & 1 deletion tests/app/service_invite/test_service_invite_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions tests/app/template/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/app/template_folder/test_template_folder_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions tests/app/test_model.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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__()

Expand Down

0 comments on commit 1f0a64d

Please sign in to comment.