mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
remove all() from statement
This commit is contained in:
@@ -773,7 +773,7 @@ def fetch_daily_volumes_for_platform(start_date, end_date):
|
|||||||
# query to return the total notifications sent per day for each channel. NB start and end dates are inclusive
|
# query to return the total notifications sent per day for each channel. NB start and end dates are inclusive
|
||||||
|
|
||||||
daily_volume_stats = (
|
daily_volume_stats = (
|
||||||
db.session.query(
|
select(
|
||||||
FactBilling.local_date,
|
FactBilling.local_date,
|
||||||
func.sum(
|
func.sum(
|
||||||
case(
|
case(
|
||||||
@@ -820,7 +820,7 @@ def fetch_daily_volumes_for_platform(start_date, end_date):
|
|||||||
)
|
)
|
||||||
|
|
||||||
aggregated_totals = (
|
aggregated_totals = (
|
||||||
db.session.query(
|
select(
|
||||||
daily_volume_stats.c.local_date.cast(db.Text).label("local_date"),
|
daily_volume_stats.c.local_date.cast(db.Text).label("local_date"),
|
||||||
func.sum(daily_volume_stats.c.sms_totals).label("sms_totals"),
|
func.sum(daily_volume_stats.c.sms_totals).label("sms_totals"),
|
||||||
func.sum(daily_volume_stats.c.sms_fragment_totals).label(
|
func.sum(daily_volume_stats.c.sms_fragment_totals).label(
|
||||||
@@ -833,10 +833,9 @@ def fetch_daily_volumes_for_platform(start_date, end_date):
|
|||||||
)
|
)
|
||||||
.group_by(daily_volume_stats.c.local_date)
|
.group_by(daily_volume_stats.c.local_date)
|
||||||
.order_by(daily_volume_stats.c.local_date)
|
.order_by(daily_volume_stats.c.local_date)
|
||||||
.all()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return aggregated_totals
|
return db.session.execute(aggregated_totals).all()
|
||||||
|
|
||||||
|
|
||||||
def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date):
|
def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from decimal import Decimal
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
from sqlalchemy import func, select
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.fact_billing_dao import (
|
from app.dao.fact_billing_dao import (
|
||||||
@@ -614,7 +615,8 @@ def test_delete_billing_data(notify_db_session):
|
|||||||
|
|
||||||
delete_billing_data_for_service_for_day("2018-01-01", service_1.id)
|
delete_billing_data_for_service_for_day("2018-01-01", service_1.id)
|
||||||
|
|
||||||
current_rows = FactBilling.query.all()
|
stmt = select(FactBilling)
|
||||||
|
current_rows = db.session.execute(stmt).all()
|
||||||
assert sorted(x.billable_units for x in current_rows) == sorted(
|
assert sorted(x.billable_units for x in current_rows) == sorted(
|
||||||
[other_day.billable_units, other_service.billable_units]
|
[other_day.billable_units, other_service.billable_units]
|
||||||
)
|
)
|
||||||
@@ -974,8 +976,8 @@ def test_fetch_usage_year_for_organization_populates_ft_billing_for_today(
|
|||||||
free_sms_fragment_limit=10,
|
free_sms_fragment_limit=10,
|
||||||
financial_year_start=current_year,
|
financial_year_start=current_year,
|
||||||
)
|
)
|
||||||
|
stmt = select(func.count()).select_from(FactBilling)
|
||||||
assert FactBilling.query.count() == 0
|
assert db.session.execute(stmt).scalar() == 0
|
||||||
|
|
||||||
create_notification(template=template, status=NotificationStatus.DELIVERED)
|
create_notification(template=template, status=NotificationStatus.DELIVERED)
|
||||||
|
|
||||||
@@ -983,7 +985,7 @@ def test_fetch_usage_year_for_organization_populates_ft_billing_for_today(
|
|||||||
organization_id=new_org.id, year=current_year
|
organization_id=new_org.id, year=current_year
|
||||||
)
|
)
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert FactBilling.query.count() == 1
|
assert db.session.execute(stmt).scalar() == 1
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2022-05-01 13:30")
|
@freeze_time("2022-05-01 13:30")
|
||||||
|
|||||||
Reference in New Issue
Block a user