fix more tests

This commit is contained in:
Kenneth Kehl
2024-10-30 12:17:59 -07:00
parent 9dfbd991d5
commit 395ddd2c47
3 changed files with 42 additions and 27 deletions

View File

@@ -1,3 +1,5 @@
from sqlalchemy import select, update
from app import db from app import db
from app.dao.dao_utils import autocommit from app.dao.dao_utils import autocommit
from app.models import ServiceDataRetention from app.models import ServiceDataRetention
@@ -5,29 +7,31 @@ from app.utils import utc_now
def fetch_service_data_retention_by_id(service_id, data_retention_id): def fetch_service_data_retention_by_id(service_id, data_retention_id):
data_retention = ServiceDataRetention.query.filter_by( stmt = select(ServiceDataRetention).where(
service_id=service_id, id=data_retention_id ServiceDataRetention.service_id == service_id,
).first() ServiceDataRetention.id == data_retention_id,
return data_retention )
return db.session.execute(stmt).scalars().first()
def fetch_service_data_retention(service_id): def fetch_service_data_retention(service_id):
data_retention_list = ( stmt = (
ServiceDataRetention.query.filter_by(service_id=service_id) select(ServiceDataRetention)
.where(ServiceDataRetention.service_id == service_id)
.order_by( .order_by(
# in the order that models.notification_types are created (email, sms, letter) # in the order that models.notification_types are created (email, sms, letter)
ServiceDataRetention.notification_type ServiceDataRetention.notification_type
) )
.all()
) )
return data_retention_list return db.session.execute(stmt).scalars().all()
def fetch_service_data_retention_by_notification_type(service_id, notification_type): def fetch_service_data_retention_by_notification_type(service_id, notification_type):
data_retention_list = ServiceDataRetention.query.filter_by( stmt = select(ServiceDataRetention).where(
service_id=service_id, notification_type=notification_type ServiceDataRetention.service_id == service_id,
).first() ServiceDataRetention.notification_type == notification_type,
return data_retention_list )
return db.session.execute(stmt).scalars().first()
@autocommit @autocommit
@@ -46,16 +50,22 @@ def insert_service_data_retention(service_id, notification_type, days_of_retenti
def update_service_data_retention( def update_service_data_retention(
service_data_retention_id, service_id, days_of_retention service_data_retention_id, service_id, days_of_retention
): ):
updated_count = ServiceDataRetention.query.filter( stmt = (
ServiceDataRetention.id == service_data_retention_id, update(ServiceDataRetention)
ServiceDataRetention.service_id == service_id, .where(
).update({"days_of_retention": days_of_retention, "updated_at": utc_now()}) ServiceDataRetention.id == service_data_retention_id,
return updated_count ServiceDataRetention.service_id == service_id,
)
.values({"days_of_retention": days_of_retention, "updated_at": utc_now()})
)
result = db.session.execute(stmt)
return result.rowcount
def fetch_service_data_retention_for_all_services_by_notification_type( def fetch_service_data_retention_for_all_services_by_notification_type(
notification_type, notification_type,
): ):
return ServiceDataRetention.query.filter( stmt = select(ServiceDataRetention).where(
ServiceDataRetention.notification_type == notification_type ServiceDataRetention.notification_type == notification_type
).all() )
return db.session.execute(stmt).scalars().all()

View File

@@ -1,11 +1,12 @@
from sqlalchemy import delete, select
from app import db from app import db
from app.models import ServiceGuestList from app.models import ServiceGuestList
def dao_fetch_service_guest_list(service_id): def dao_fetch_service_guest_list(service_id):
return ServiceGuestList.query.filter( stmt = select(ServiceGuestList).where(ServiceGuestList.service_id == service_id)
ServiceGuestList.service_id == service_id return db.session.execute(stmt).scalars().all()
).all()
def dao_add_and_commit_guest_list_contacts(objs): def dao_add_and_commit_guest_list_contacts(objs):
@@ -14,6 +15,7 @@ def dao_add_and_commit_guest_list_contacts(objs):
def dao_remove_service_guest_list(service_id): def dao_remove_service_guest_list(service_id):
return ServiceGuestList.query.filter( stmt = delete(ServiceGuestList).where(ServiceGuestList.service_id == service_id)
ServiceGuestList.service_id == service_id result = db.session.execute(stmt)
).delete() db.session.commit()
return result.rowcount

View File

@@ -1,13 +1,16 @@
from sqlalchemy import select
from app import db from app import db
from app.dao.dao_utils import autocommit from app.dao.dao_utils import autocommit
from app.models import WebauthnCredential from app.models import WebauthnCredential
def dao_get_webauthn_credential_by_user_and_id(user_id, webauthn_credential_id): def dao_get_webauthn_credential_by_user_and_id(user_id, webauthn_credential_id):
return WebauthnCredential.query.filter( stmt = select(WebauthnCredential).where(
WebauthnCredential.user_id == user_id, WebauthnCredential.user_id == user_id,
WebauthnCredential.id == webauthn_credential_id, WebauthnCredential.id == webauthn_credential_id,
).one() )
return db.session.execute(stmt).scalars().one()
@autocommit @autocommit