This commit is contained in:
Kenneth Kehl
2024-11-15 11:39:51 -08:00
parent 98ee86fcb5
commit 703a29f577
5 changed files with 36 additions and 30 deletions

View File

@@ -6,7 +6,7 @@ from flask import Blueprint, abort, current_app, jsonify, request
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
from app import redis_store from app import db, redis_store
from app.config import QueueNames from app.config import QueueNames
from app.dao.permissions_dao import permission_dao from app.dao.permissions_dao import permission_dao
from app.dao.service_user_dao import dao_get_service_user, dao_update_service_user from app.dao.service_user_dao import dao_get_service_user, dao_update_service_user
@@ -120,7 +120,7 @@ def update_user_attribute(user_id):
reply_to = get_sms_reply_to_for_notify_service(recipient, template) reply_to = get_sms_reply_to_for_notify_service(recipient, template)
else: else:
return jsonify(data=user_to_update.serialize()), 200 return jsonify(data=user_to_update.serialize()), 200
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"]) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
personalisation = { personalisation = {
"name": user_to_update.name, "name": user_to_update.name,
"servicemanagername": updated_by.name, "servicemanagername": updated_by.name,
@@ -393,7 +393,7 @@ def send_user_confirm_new_email(user_id):
template = dao_get_template_by_id( template = dao_get_template_by_id(
current_app.config["CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID"] current_app.config["CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID"]
) )
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"]) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
personalisation = { personalisation = {
"name": user_to_send_to.name, "name": user_to_send_to.name,
"url": _create_confirmation_url( "url": _create_confirmation_url(
@@ -434,7 +434,7 @@ def send_new_user_email_verification(user_id):
template = dao_get_template_by_id( template = dao_get_template_by_id(
current_app.config["NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID"] current_app.config["NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID"]
) )
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"]) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
current_app.logger.info("template.id is {}".format(template.id)) current_app.logger.info("template.id is {}".format(template.id))
current_app.logger.info("service.id is {}".format(service.id)) current_app.logger.info("service.id is {}".format(service.id))
@@ -487,7 +487,7 @@ def send_already_registered_email(user_id):
template = dao_get_template_by_id( template = dao_get_template_by_id(
current_app.config["ALREADY_REGISTERED_EMAIL_TEMPLATE_ID"] current_app.config["ALREADY_REGISTERED_EMAIL_TEMPLATE_ID"]
) )
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"]) service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
current_app.logger.info("template.id is {}".format(template.id)) current_app.logger.info("template.id is {}".format(template.id))
current_app.logger.info("service.id is {}".format(service.id)) current_app.logger.info("service.id is {}".format(service.id))

View File

@@ -74,12 +74,12 @@ def test_create_user(notify_db_session, phone_number, expected_phone_number):
stmt = select(func.count(User.id)) stmt = select(func.count(User.id))
assert db.session.execute(stmt).scalar() == 1 assert db.session.execute(stmt).scalar() == 1
stmt = select(User) stmt = select(User)
user_query = db.session.execute(stmt).scalars().first() user = db.session.execute(stmt).scalars().first()
assert user_query.email_address == email assert user.email_address == email
assert user_query.id == user.id assert user.id == user.id
assert user_query.mobile_number == expected_phone_number assert user.mobile_number == expected_phone_number
assert user_query.email_access_validated_at == utc_now() assert user.email_access_validated_at == utc_now()
assert not user_query.platform_admin assert not user.platform_admin
def test_get_all_users(notify_db_session): def test_get_all_users(notify_db_session):

View File

@@ -855,7 +855,7 @@ def test_should_delete_notification_and_return_error_if_redis_fails(
mocked.assert_called_once_with([fake_uuid], queue=queue_name) mocked.assert_called_once_with([fake_uuid], queue=queue_name)
assert not notifications_dao.get_notification_by_id(fake_uuid) assert not notifications_dao.get_notification_by_id(fake_uuid)
assert not NotificationHistory.query.get(fake_uuid) assert not db.session.get(NotificationHistory, fake_uuid)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -1065,7 +1065,7 @@ def test_should_error_if_notification_type_does_not_match_template_type(
def test_create_template_raises_invalid_request_exception_with_missing_personalisation( def test_create_template_raises_invalid_request_exception_with_missing_personalisation(
sample_template_with_placeholders, sample_template_with_placeholders,
): ):
template = Template.query.get(sample_template_with_placeholders.id) template = db.session.get(Template, sample_template_with_placeholders.id)
from app.notifications.rest import create_template_object_for_notification from app.notifications.rest import create_template_object_for_notification
with pytest.raises(InvalidRequest) as e: with pytest.raises(InvalidRequest) as e:
@@ -1078,7 +1078,7 @@ def test_create_template_doesnt_raise_with_too_much_personalisation(
): ):
from app.notifications.rest import create_template_object_for_notification from app.notifications.rest import create_template_object_for_notification
template = Template.query.get(sample_template_with_placeholders.id) template = db.session.get(Template, sample_template_with_placeholders.id)
create_template_object_for_notification(template, {"name": "Jo", "extra": "stuff"}) create_template_object_for_notification(template, {"name": "Jo", "extra": "stuff"})
@@ -1095,7 +1095,7 @@ def test_create_template_raises_invalid_request_when_content_too_large(
sample = create_template( sample = create_template(
sample_service, template_type=template_type, content="((long_text))" sample_service, template_type=template_type, content="((long_text))"
) )
template = Template.query.get(sample.id) template = db.session.get(Template, sample.id)
from app.notifications.rest import create_template_object_for_notification from app.notifications.rest import create_template_object_for_notification
try: try:
@@ -1377,5 +1377,5 @@ def test_send_notification_should_set_client_reference_from_placeholder(
notification_id = send_one_off_notification(sample_letter_template.service_id, data) notification_id = send_one_off_notification(sample_letter_template.service_id, data)
assert deliver_mock.called assert deliver_mock.called
notification = Notification.query.get(notification_id["id"]) notification = db.session.get(Notification, notification_id["id"])
assert notification.client_reference == reference_paceholder assert notification.client_reference == reference_paceholder

View File

@@ -415,7 +415,7 @@ def test_create_service(
assert json_resp["data"]["email_from"] == "created.service" assert json_resp["data"]["email_from"] == "created.service"
assert json_resp["data"]["count_as_live"] is expected_count_as_live assert json_resp["data"]["count_as_live"] is expected_count_as_live
service_db = Service.query.get(json_resp["data"]["id"]) service_db = db.session.get(Service, json_resp["data"]["id"])
assert service_db.name == "created service" assert service_db.name == "created service"
json_resp = admin_request.get( json_resp = admin_request.get(
@@ -2832,7 +2832,7 @@ def test_send_one_off_notification(sample_service, admin_request, mocker):
_expected_status=201, _expected_status=201,
) )
noti = Notification.query.one() noti = db.session.execute(select(Notification)).scalars().one()
assert response["id"] == str(noti.id) assert response["id"] == str(noti.id)
@@ -3022,7 +3022,7 @@ def test_verify_reply_to_email_address_should_send_verification_email(
_expected_status=201, _expected_status=201,
) )
notification = Notification.query.first() notification = db.session.execute(select(Notification)).scalars().first()
assert notification.template_id == verify_reply_to_address_email_template.id assert notification.template_id == verify_reply_to_address_email_template.id
assert response["data"] == {"id": str(notification.id)} assert response["data"] == {"id": str(notification.id)}
mocked.assert_called_once_with( mocked.assert_called_once_with(
@@ -3290,7 +3290,7 @@ def test_add_service_sms_sender_when_it_is_an_inbound_number_updates_the_only_ex
], ],
) )
assert response.status_code == 201 assert response.status_code == 201
updated_number = InboundNumber.query.get(inbound_number.id) updated_number = db.session.get(InboundNumber, inbound_number.id)
assert updated_number.service_id == service.id assert updated_number.service_id == service.id
resp_json = json.loads(response.get_data(as_text=True)) resp_json = json.loads(response.get_data(as_text=True))
assert resp_json["sms_sender"] == inbound_number.number assert resp_json["sms_sender"] == inbound_number.number
@@ -3321,7 +3321,7 @@ def test_add_service_sms_sender_when_it_is_an_inbound_number_inserts_new_sms_sen
], ],
) )
assert response.status_code == 201 assert response.status_code == 201
updated_number = InboundNumber.query.get(inbound_number.id) updated_number = db.session.get(InboundNumber, inbound_number.id)
assert updated_number.service_id == service.id assert updated_number.service_id == service.id
resp_json = json.loads(response.get_data(as_text=True)) resp_json = json.loads(response.get_data(as_text=True))
assert resp_json["sms_sender"] == inbound_number.number assert resp_json["sms_sender"] == inbound_number.number

View File

@@ -135,7 +135,7 @@ def test_update_jobs_archived_flag(notify_db_session, notify_api):
right_now, right_now,
], ],
) )
jobs = Job.query.all() jobs = db.session.execute(select(Job)).scalars().all()
assert len(jobs) == 1 assert len(jobs) == 1
for job in jobs: for job in jobs:
assert job.archived is True assert job.archived is True
@@ -177,7 +177,7 @@ def test_populate_organization_agreement_details_from_file(
org_count = _get_organization_query_count() org_count = _get_organization_query_count()
assert org_count == 1 assert org_count == 1
org = Organization.query.one() org = db.session.execute(select(Organization)).scalars().one()
org.agreement_signed = True org.agreement_signed = True
notify_db_session.commit() notify_db_session.commit()
@@ -195,7 +195,7 @@ def test_populate_organization_agreement_details_from_file(
org_count = _get_organization_query_count() org_count = _get_organization_query_count()
assert org_count == 1 assert org_count == 1
org = Organization.query.one() org = db.session.execute(select(Organization)).scalars().one()
assert org.agreement_signed_on_behalf_of_name == "bob" assert org.agreement_signed_on_behalf_of_name == "bob"
os.remove(file_name) os.remove(file_name)
@@ -382,10 +382,16 @@ def test_populate_annual_billing_with_defaults_sets_free_allowance_to_zero_if_pr
populate_annual_billing_with_defaults, ["-y", 2022] populate_annual_billing_with_defaults, ["-y", 2022]
) )
results = AnnualBilling.query.filter( results = (
AnnualBilling.financial_year_start == 2022, db.session.execute(
AnnualBilling.service_id == service.id, select(AnnualBilling).where(
).all() AnnualBilling.financial_year_start == 2022,
AnnualBilling.service_id == service.id,
)
)
.scalars()
.all()
)
assert len(results) == 1 assert len(results) == 1
assert results[0].free_sms_fragment_limit == 0 assert results[0].free_sms_fragment_limit == 0
@@ -402,7 +408,7 @@ def test_update_template(notify_db_session, email_2fa_code_template):
"", "",
) )
t = Template.query.all() t = db.session.execute(select(Template)).scalars().all()
assert t[0].name == "Example text message template!" assert t[0].name == "Example text message template!"
@@ -422,7 +428,7 @@ def test_create_service_command(notify_db_session, notify_api):
], ],
) )
user = User.query.first() user = db.session.execute(select(User)).scalars().first()
stmt = select(func.count()).select_from(Service) stmt = select(func.count()).select_from(Service)
service_count = db.session.execute(stmt).scalar() or 0 service_count = db.session.execute(stmt).scalar() or 0