mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
more tests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
from sqlalchemy import select
|
||||
|
||||
from app import db
|
||||
from app.dao.annual_billing_dao import (
|
||||
dao_create_or_update_annual_billing_for_year,
|
||||
dao_get_free_sms_fragment_limit_for_year,
|
||||
@@ -87,7 +89,7 @@ def test_set_default_free_allowance_for_service(
|
||||
|
||||
set_default_free_allowance_for_service(service=service, year_start=year)
|
||||
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
annual_billing = db.session.execute(select(AnnualBilling)).scalars().all()
|
||||
|
||||
assert len(annual_billing) == 1
|
||||
assert annual_billing[0].service_id == service.id
|
||||
@@ -109,7 +111,7 @@ def test_set_default_free_allowance_for_service_using_correct_year(
|
||||
@freeze_time("2021-04-01 14:02:00")
|
||||
def test_set_default_free_allowance_for_service_updates_existing_year(sample_service):
|
||||
set_default_free_allowance_for_service(service=sample_service, year_start=None)
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
annual_billing = db.session.execute(select(AnnualBilling)).scalars().all()
|
||||
assert not sample_service.organization_type
|
||||
assert len(annual_billing) == 1
|
||||
assert annual_billing[0].service_id == sample_service.id
|
||||
@@ -118,7 +120,7 @@ def test_set_default_free_allowance_for_service_updates_existing_year(sample_ser
|
||||
sample_service.organization_type = OrganizationType.FEDERAL
|
||||
|
||||
set_default_free_allowance_for_service(service=sample_service, year_start=None)
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
annual_billing = db.session.execute(select(AnnualBilling)).scalars().all()
|
||||
assert len(annual_billing) == 1
|
||||
assert annual_billing[0].service_id == sample_service.id
|
||||
assert annual_billing[0].free_sms_fragment_limit == 150000
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from sqlalchemy import select
|
||||
|
||||
from app import db
|
||||
from app.dao.email_branding_dao import (
|
||||
dao_get_email_branding_by_id,
|
||||
dao_get_email_branding_by_name,
|
||||
@@ -27,14 +30,14 @@ def test_update_email_branding(notify_db_session):
|
||||
updated_name = "new name"
|
||||
create_email_branding()
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
email_branding = db.session.execute(select(EmailBranding)).scalars().all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert email_branding[0].name != updated_name
|
||||
|
||||
dao_update_email_branding(email_branding[0], name=updated_name)
|
||||
|
||||
email_branding = EmailBranding.query.all()
|
||||
email_branding = db.session.execute(select(EmailBranding)).scalars().all()
|
||||
|
||||
assert len(email_branding) == 1
|
||||
assert email_branding[0].name == updated_name
|
||||
@@ -42,5 +45,5 @@ def test_update_email_branding(notify_db_session):
|
||||
|
||||
def test_email_branding_has_no_domain(notify_db_session):
|
||||
create_email_branding()
|
||||
email_branding = EmailBranding.query.all()
|
||||
email_branding = db.session.execute(select(EmailBranding)).scalars().all()
|
||||
assert not hasattr(email_branding, "domain")
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app import db
|
||||
from app.dao.service_data_retention_dao import (
|
||||
fetch_service_data_retention,
|
||||
fetch_service_data_retention_by_id,
|
||||
@@ -97,7 +99,7 @@ def test_insert_service_data_retention(sample_service):
|
||||
days_of_retention=3,
|
||||
)
|
||||
|
||||
results = ServiceDataRetention.query.all()
|
||||
results = db.session.execute(select(ServiceDataRetention)).scalars().all()
|
||||
assert len(results) == 1
|
||||
assert results[0].service_id == sample_service.id
|
||||
assert results[0].notification_type == NotificationType.EMAIL
|
||||
@@ -131,7 +133,7 @@ def test_update_service_data_retention(sample_service):
|
||||
days_of_retention=5,
|
||||
)
|
||||
assert updated_count == 1
|
||||
results = ServiceDataRetention.query.all()
|
||||
results = db.session.execute(select(ServiceDataRetention)).scalars().all()
|
||||
assert len(results) == 1
|
||||
assert results[0].id == data_retention.id
|
||||
assert results[0].service_id == sample_service.id
|
||||
@@ -150,7 +152,7 @@ def test_update_service_data_retention_does_not_update_if_row_does_not_exist(
|
||||
days_of_retention=5,
|
||||
)
|
||||
assert updated_count == 0
|
||||
assert len(ServiceDataRetention.query.all()) == 0
|
||||
assert len(db.session.execute(select(ServiceDataRetention)).scalars().all()) == 0
|
||||
|
||||
|
||||
def test_update_service_data_retention_does_not_update_row_if_data_retention_is_for_different_service(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import pytest
|
||||
from flask import json
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app import db
|
||||
from app.celery.process_ses_receipts_tasks import (
|
||||
check_and_queue_callback_task,
|
||||
handle_complaint,
|
||||
@@ -35,7 +37,7 @@ def test_ses_callback_should_not_set_status_once_status_is_delivered(
|
||||
def test_process_ses_results_in_complaint(sample_email_template):
|
||||
notification = create_notification(template=sample_email_template, reference="ref1")
|
||||
handle_complaint(json.loads(ses_complaint_callback()["Message"]))
|
||||
complaints = Complaint.query.all()
|
||||
complaints = db.session.execute(select(Complaint)).scalars().all()
|
||||
assert len(complaints) == 1
|
||||
assert complaints[0].notification_id == notification.id
|
||||
|
||||
@@ -43,7 +45,7 @@ def test_process_ses_results_in_complaint(sample_email_template):
|
||||
def test_handle_complaint_does_not_raise_exception_if_reference_is_missing(notify_api):
|
||||
response = json.loads(ses_complaint_callback_malformed_message_id()["Message"])
|
||||
handle_complaint(response)
|
||||
assert len(Complaint.query.all()) == 0
|
||||
assert len(db.session.execute(select(Complaint)).scalars().all()) == 0
|
||||
|
||||
|
||||
def test_handle_complaint_does_raise_exception_if_notification_not_found(notify_api):
|
||||
@@ -57,7 +59,7 @@ def test_process_ses_results_in_complaint_if_notification_history_does_not_exist
|
||||
):
|
||||
notification = create_notification(template=sample_email_template, reference="ref1")
|
||||
handle_complaint(json.loads(ses_complaint_callback()["Message"]))
|
||||
complaints = Complaint.query.all()
|
||||
complaints = db.session.execute(select(Complaint)).scalars().all()
|
||||
assert len(complaints) == 1
|
||||
assert complaints[0].notification_id == notification.id
|
||||
|
||||
@@ -69,7 +71,7 @@ def test_process_ses_results_in_complaint_if_notification_does_not_exist(
|
||||
template=sample_email_template, reference="ref1"
|
||||
)
|
||||
handle_complaint(json.loads(ses_complaint_callback()["Message"]))
|
||||
complaints = Complaint.query.all()
|
||||
complaints = db.session.execute(select(Complaint)).scalars().all()
|
||||
assert len(complaints) == 1
|
||||
assert complaints[0].notification_id == notification.id
|
||||
|
||||
@@ -80,7 +82,7 @@ def test_process_ses_results_in_complaint_save_complaint_with_null_complaint_typ
|
||||
notification = create_notification(template=sample_email_template, reference="ref1")
|
||||
msg = json.loads(ses_complaint_callback_with_missing_complaint_type()["Message"])
|
||||
handle_complaint(msg)
|
||||
complaints = Complaint.query.all()
|
||||
complaints = db.session.execute(select(Complaint)).scalars().all()
|
||||
assert len(complaints) == 1
|
||||
assert complaints[0].notification_id == notification.id
|
||||
assert not complaints[0].complaint_type
|
||||
|
||||
@@ -599,7 +599,7 @@ def test_post_link_service_to_organization_inserts_annual_billing(
|
||||
data = {"service_id": str(sample_service.id)}
|
||||
organization = create_organization(organization_type=OrganizationType.FEDERAL)
|
||||
assert len(organization.services) == 0
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
assert len(db.session.execute(select(AnnualBilling)).scalars().all()) == 0
|
||||
admin_request.post(
|
||||
"organization.link_service_to_organization",
|
||||
_data=data,
|
||||
@@ -607,7 +607,7 @@ def test_post_link_service_to_organization_inserts_annual_billing(
|
||||
_expected_status=204,
|
||||
)
|
||||
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
annual_billing = db.session.execute(select(AnnualBilling)).scalars().all()
|
||||
assert len(annual_billing) == 1
|
||||
assert annual_billing[0].free_sms_fragment_limit == 150000
|
||||
|
||||
@@ -624,7 +624,7 @@ def test_post_link_service_to_organization_rollback_service_if_annual_billing_up
|
||||
|
||||
organization = create_organization(organization_type=OrganizationType.FEDERAL)
|
||||
assert len(organization.services) == 0
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
assert len(db.session.execute(select(AnnualBilling)).scalars().all()) == 0
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
admin_request.post(
|
||||
"organization.link_service_to_organization",
|
||||
@@ -633,7 +633,7 @@ def test_post_link_service_to_organization_rollback_service_if_annual_billing_up
|
||||
)
|
||||
assert not sample_service.organization_type
|
||||
assert len(organization.services) == 0
|
||||
assert len(AnnualBilling.query.all()) == 0
|
||||
assert len(db.session.execute(select(AnnualBilling)).scalars().all()) == 0
|
||||
|
||||
|
||||
@freeze_time("2021-09-24 13:30")
|
||||
@@ -663,7 +663,7 @@ def test_post_link_service_to_another_org(
|
||||
assert not sample_organization.services
|
||||
assert len(new_org.services) == 1
|
||||
assert sample_service.organization_type == OrganizationType.FEDERAL
|
||||
annual_billing = AnnualBilling.query.all()
|
||||
annual_billing = db.session.execute(select(AnnualBilling)).scalars().all()
|
||||
assert len(annual_billing) == 1
|
||||
assert annual_billing[0].free_sms_fragment_limit == 150000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user