From 38a2a87a15bd8cb6dcf70baba1a6fca469298545 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 21 Oct 2024 08:01:57 -0700 Subject: [PATCH] fix test code --- app/dao/complaint_dao.py | 10 ++++++---- tests/app/dao/test_inbound_numbers_dao.py | 5 ++++- tests/app/dao/test_inbound_sms_dao.py | 10 +++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/dao/complaint_dao.py b/app/dao/complaint_dao.py index 2da93b681..63b7487fb 100644 --- a/app/dao/complaint_dao.py +++ b/app/dao/complaint_dao.py @@ -16,13 +16,15 @@ def save_complaint(complaint): def fetch_paginated_complaints(page=1): - # return Complaint.query.order_by(desc(Complaint.created_at)).paginate( - # page=page, per_page=current_app.config["PAGE_SIZE"] - # ) page_size = current_app.config["PAGE_SIZE"] total_count = db.session.scalar(select(func.count()).select_from(Complaint)) offset = (page - 1) * page_size - stmt = select(Complaint).order_by(desc(Complaint.created_at)).offset(offset).limit(page_size) + stmt = ( + select(Complaint) + .order_by(desc(Complaint.created_at)) + .offset(offset) + .limit(page_size) + ) result = db.session.execute(stmt).scalars().all() pagination = Pagination(result, page=page, per_page=page_size, total=total_count) return pagination diff --git a/tests/app/dao/test_inbound_numbers_dao.py b/tests/app/dao/test_inbound_numbers_dao.py index ce3fd6245..ade1f7f94 100644 --- a/tests/app/dao/test_inbound_numbers_dao.py +++ b/tests/app/dao/test_inbound_numbers_dao.py @@ -1,6 +1,8 @@ import pytest +from sqlalchemy import select from sqlalchemy.exc import IntegrityError +from app import db from app.dao.inbound_numbers_dao import ( dao_allocate_number_for_service, dao_get_available_inbound_numbers, @@ -35,7 +37,8 @@ def test_set_service_id_on_inbound_number(notify_db_session, sample_inbound_numb dao_set_inbound_number_to_service(service.id, numbers[0]) - res = InboundNumber.query.filter(InboundNumber.service_id == service.id).all() + stmt = select(InboundNumber).filter(InboundNumber.service_id == service.id) + res = db.session.execute(stmt).all() assert len(res) == 1 assert res[0].service_id == service.id diff --git a/tests/app/dao/test_inbound_sms_dao.py b/tests/app/dao/test_inbound_sms_dao.py index ff8bff0dc..3bc590123 100644 --- a/tests/app/dao/test_inbound_sms_dao.py +++ b/tests/app/dao/test_inbound_sms_dao.py @@ -2,6 +2,7 @@ from datetime import datetime from itertools import product from freezegun import freeze_time +from sqlalchemy import select from app import db from app.dao.inbound_sms_dao import ( @@ -141,7 +142,8 @@ def test_should_delete_inbound_sms_according_to_data_retention(notify_db_session deleted_count = delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 7 # four deleted for the 3-day service, two for the default seven days one, one for the 30 day @@ -171,7 +173,8 @@ def test_insert_into_inbound_sms_history_when_deleting_inbound_sms(sample_servic create_inbound_sms(sample_service, created_at=datetime(2019, 12, 19, 20, 19)) delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 1 for key_name in [ @@ -226,7 +229,8 @@ def test_delete_inbound_sms_older_than_retention_does_nothing_when_database_conf delete_inbound_sms_older_than_retention() - history = InboundSmsHistory.query.all() + stmt = select(InboundSmsHistory) + history = db.session.execute(stmt).all() assert len(history) == 1 assert history[0].id == inbound_sms_id