This commit is contained in:
Kenneth Kehl
2024-11-15 13:42:27 -08:00
parent 3eadfb2242
commit bc4d4c9735
8 changed files with 70 additions and 51 deletions

View File

@@ -2,8 +2,9 @@ import json
from unittest.mock import ANY
from freezegun import freeze_time
from sqlalchemy import select
from app import encryption
from app import db, encryption
from app.celery.process_ses_receipts_tasks import (
process_ses_results,
remove_emails_from_bounce,
@@ -168,7 +169,7 @@ def test_process_ses_results_in_complaint(sample_email_template, mocker):
)
process_ses_results(response=ses_complaint_callback())
assert mocked.call_count == 0
complaints = Complaint.query.all()
complaints = db.session.execute(select(Complaint)).scalars().all()
assert len(complaints) == 1
assert complaints[0].notification_id == notification.id
@@ -420,7 +421,7 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api(
assert send_mock.call_count == 1
assert encryption.decrypt(send_mock.call_args[0][0][0]) == {
"complaint_date": "2018-06-05T13:59:58.000000Z",
"complaint_id": str(Complaint.query.one().id),
"complaint_id": str(db.session.execute(select(Complaint)).scalars().one().id),
"notification_id": str(notification.id),
"reference": None,
"service_callback_api_bearer_token": "some_super_secret",

View File

@@ -115,12 +115,12 @@ def test_save_invited_user_sets_status_to_cancelled(
notify_db_session, sample_invited_user
):
assert _get_invited_user_count() == 1
saved = InvitedUser.query.get(sample_invited_user.id)
saved = db.session.get(InvitedUser, sample_invited_user.id)
assert saved.status == InvitedUserStatus.PENDING
saved.status = InvitedUserStatus.CANCELLED
save_invited_user(saved)
assert _get_invited_user_count() == 1
cancelled_invited_user = InvitedUser.query.get(sample_invited_user.id)
cancelled_invited_user = db.session.get(InvitedUser, sample_invited_user.id)
assert cancelled_invited_user.status == InvitedUserStatus.CANCELLED

View File

@@ -197,7 +197,7 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
assert str(sample_notification.id) in str(e.value)
send_mock.assert_not_called()
assert (
Notification.query.get(sample_notification.id).status
db.session.get(Notification, sample_notification.id).status
== NotificationStatus.TECHNICAL_FAILURE
)
@@ -221,7 +221,7 @@ def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in
assert str(sample_notification.id) in str(e.value)
send_mock.assert_not_called()
assert (
Notification.query.get(sample_notification.id).status
db.session.get(Notification, sample_notification.id).status
== NotificationStatus.TECHNICAL_FAILURE
)

View File

@@ -100,9 +100,9 @@ def test_persist_notification_creates_and_save_to_db(
reply_to_text=sample_template.service.get_default_sms_sender(),
)
assert Notification.query.get(notification.id) is not None
assert db.session.get(Notification, notification.id) is not None
notification_from_db = Notification.query.one()
notification_from_db = db.session.execute(select(Notification)).scalars().one()
assert notification_from_db.id == notification.id
assert notification_from_db.template_id == notification.template_id

View File

@@ -64,7 +64,7 @@ def test_receive_notification_returns_received_to_sns(
prom_counter_labels_mock.assert_called_once_with("sns")
prom_counter_labels_mock.return_value.inc.assert_called_once_with()
inbound_sms_id = InboundSms.query.all()[0].id
inbound_sms_id = db.session.execute(select(InboundSms)).scalars().all()[0].id
mocked.assert_called_once_with(
[str(inbound_sms_id), str(sample_service_full_permissions.id)],
queue="notify-internal-tasks",
@@ -136,7 +136,7 @@ def test_receive_notification_without_permissions_does_not_create_inbound_even_w
response = sns_post(client, data)
assert response.status_code == 200
assert len(InboundSms.query.all()) == 0
assert len(db.session.execute(select(InboundSms)).scalars().all()) == 0
assert mocked_has_permissions.called
mocked_send_inbound_sms.assert_not_called()

View File

@@ -27,7 +27,13 @@ def test_api_key_should_create_new_api_key_for_service(notify_api, sample_servic
)
assert response.status_code == 201
assert "data" in json.loads(response.get_data(as_text=True))
saved_api_key = ApiKey.query.filter_by(service_id=sample_service.id).first()
saved_api_key = (
db.session.execute(
select(ApiKey).filter_by(service_id=sample_service.id)
)
.scalars()
.first()
)
assert saved_api_key.service_id == sample_service.id
assert saved_api_key.name == "some secret name"
@@ -81,7 +87,7 @@ def test_revoke_should_expire_api_key_for_service(notify_api, sample_api_key):
headers=[auth_header],
)
assert response.status_code == 202
api_keys_for_service = ApiKey.query.get(sample_api_key.id)
api_keys_for_service = db.session.get(ApiKey, sample_api_key.id)
assert api_keys_for_service.expiry_date is not None