This commit is contained in:
Kenneth Kehl
2024-11-18 09:26:04 -08:00
parent 4ef1847baf
commit 3168f28920
5 changed files with 17 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
from flask import Blueprint, jsonify, request
from app import db
from app.billing.billing_schemas import (
create_or_update_free_sms_fragment_limit_schema,
serialize_ft_billing_remove_emails,
@@ -60,7 +61,7 @@ def get_free_sms_fragment_limit(service_id):
)
if annual_billing is None:
service = Service.query.get(service_id)
service = db.session.get(Service, service_id)
# An entry does not exist in annual_billing table for that service and year.
# Set the annual billing to the default free allowance based on the organization type of the service.

View File

@@ -1,10 +1,10 @@
from datetime import timedelta
from flask import current_app
from sqlalchemy import between
from sqlalchemy import between, select
from sqlalchemy.exc import SQLAlchemyError
from app import notify_celery, zendesk_client
from app import db, notify_celery, zendesk_client
from app.celery.tasks import (
get_recipient_csv_and_template_and_sender_id,
process_incomplete_jobs,
@@ -105,19 +105,22 @@ def check_job_status():
thirty_minutes_ago = utc_now() - timedelta(minutes=30)
thirty_five_minutes_ago = utc_now() - timedelta(minutes=35)
incomplete_in_progress_jobs = Job.query.filter(
incomplete_in_progress_jobs = select(Job).where(
Job.job_status == JobStatus.IN_PROGRESS,
between(Job.processing_started, thirty_five_minutes_ago, thirty_minutes_ago),
)
incomplete_pending_jobs = Job.query.filter(
incomplete_pending_jobs = select(Job).where(
Job.job_status == JobStatus.PENDING,
Job.scheduled_for.isnot(None),
between(Job.scheduled_for, thirty_five_minutes_ago, thirty_minutes_ago),
)
jobs_not_complete_after_30_minutes = (
incomplete_in_progress_jobs.union(incomplete_pending_jobs)
db.session.execute(
select(incomplete_in_progress_jobs.union(incomplete_pending_jobs))
)
.order_by(Job.processing_started, Job.scheduled_for)
.scalars()
.all()
)

View File

@@ -6,7 +6,7 @@ from urllib.parse import unquote
from flask import Blueprint, current_app, jsonify, request
from itsdangerous import BadData, SignatureExpired
from app import redis_store
from app import db, redis_store
from app.config import QueueNames
from app.dao.invited_user_dao import (
get_expired_invite_by_service_and_id,
@@ -39,7 +39,7 @@ def _create_service_invite(invited_user, nonce, state):
template = dao_get_template_by_id(template_id)
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
# The raw permissions are in the form "a,b,c,d"
# but need to be in the form ["a", "b", "c", "d"]

View File

@@ -1,8 +1,10 @@
import uuid
import pytest
from sqlalchemy import select
from sqlalchemy.exc import SQLAlchemyError
from app import db
from app.dao.service_email_reply_to_dao import (
add_reply_to_email_address_for_service,
archive_reply_to_email_address,
@@ -186,7 +188,7 @@ def test_update_reply_to_email_address(sample_service):
email_address="change_address@email.com",
is_default=True,
)
updated_reply_to = ServiceEmailReplyTo.query.get(first_reply_to.id)
updated_reply_to = db.session.get(ServiceEmailReplyTo, first_reply_to.id)
assert updated_reply_to.email_address == "change_address@email.com"
assert updated_reply_to.updated_at
@@ -206,7 +208,7 @@ def test_update_reply_to_email_address_set_updated_to_default(sample_service):
is_default=True,
)
results = ServiceEmailReplyTo.query.all()
results = db.session.execute(select(ServiceEmailReplyTo)).scalars().all()
assert len(results) == 2
for x in results:
if x.email_address == "change_address@email.com":

View File

@@ -23,7 +23,7 @@ def test_send_notification_to_service_users_persists_notifications_correctly(
service_id=sample_service.id, template_id=template.id
)
notification = Notification.query.one()
notification = db.session.execute(select(Notification)).scalars().one()
stmt = select(func.count()).select_from(Notification)
count = db.session.execute(stmt).scalar() or 0