This commit is contained in:
Kenneth Kehl
2024-11-18 13:52:20 -08:00
parent 14bfcd3f42
commit d2d5fa71ef
2 changed files with 7 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
from sqlalchemy import select
from sqlalchemy.dialects.postgresql import insert from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.sql.expression import case from sqlalchemy.sql.expression import case
@@ -33,8 +34,8 @@ def insert_update_processing_time(processing_time):
def get_processing_time_percentage_for_date_range(start_date, end_date): def get_processing_time_percentage_for_date_range(start_date, end_date):
query = ( stmt = (
db.session.query( select(
FactProcessingTime.local_date.cast(db.Text).label("date"), FactProcessingTime.local_date.cast(db.Text).label("date"),
FactProcessingTime.messages_total, FactProcessingTime.messages_total,
FactProcessingTime.messages_within_10_secs, FactProcessingTime.messages_within_10_secs,
@@ -52,11 +53,11 @@ def get_processing_time_percentage_for_date_range(start_date, end_date):
(FactProcessingTime.messages_total == 0, 100.0), (FactProcessingTime.messages_total == 0, 100.0),
).label("percentage"), ).label("percentage"),
) )
.filter( .where(
FactProcessingTime.local_date >= start_date, FactProcessingTime.local_date >= start_date,
FactProcessingTime.local_date <= end_date, FactProcessingTime.local_date <= end_date,
) )
.order_by(FactProcessingTime.local_date) .order_by(FactProcessingTime.local_date)
) )
return db.session.execute(query).scalars().all() return db.session.execute(stmt).scalars().all()

View File

@@ -320,9 +320,7 @@ def test_dao_get_paginated_inbound_sms_for_service_for_public_api_older_than_ret
) )
expected_inbound_sms = reversed_inbound_sms[2:] expected_inbound_sms = reversed_inbound_sms[2:]
print(f"EXPECTED {expected_inbound_sms}") assert expected_inbound_sms == inbound_from_db.items
print(f"ACTUAL {inbound_from_db.items}")
assert expected_inbound_sms == inbound_from_db
def test_dao_get_paginated_inbound_sms_for_service_for_public_api_older_than_end_returns_empty_list( def test_dao_get_paginated_inbound_sms_for_service_for_public_api_older_than_end_returns_empty_list(
@@ -339,8 +337,7 @@ def test_dao_get_paginated_inbound_sms_for_service_for_public_api_older_than_end
inbound_from_db = dao_get_paginated_inbound_sms_for_service_for_public_api( inbound_from_db = dao_get_paginated_inbound_sms_for_service_for_public_api(
sample_service.id, older_than=reversed_inbound_sms[1].id, page_size=2 sample_service.id, older_than=reversed_inbound_sms[1].id, page_size=2
) )
print(f"HERE IS INBOUND FROM DB {inbound_from_db.items}") assert inbound_from_db.items == []
assert inbound_from_db.has_next is False
def test_most_recent_inbound_sms_only_returns_most_recent_for_each_number( def test_most_recent_inbound_sms_only_returns_most_recent_for_each_number(