This commit is contained in:
Kenneth Kehl
2024-10-31 14:25:35 -07:00
parent 3dd21705b8
commit 78ac1ee094
4 changed files with 36 additions and 15 deletions

View File

@@ -277,7 +277,7 @@
"filename": "tests/app/notifications/test_receive_notification.py",
"hashed_secret": "913a73b565c8e2c8ed94497580f619397709b8b6",
"is_verified": false,
"line_number": 24,
"line_number": 26,
"is_secret": false
},
{
@@ -285,7 +285,7 @@
"filename": "tests/app/notifications/test_receive_notification.py",
"hashed_secret": "d70eab08607a4d05faa2d0d6647206599e9abc65",
"is_verified": false,
"line_number": 54,
"line_number": 56,
"is_secret": false
}
],
@@ -384,5 +384,5 @@
}
]
},
"generated_at": "2024-10-31T18:48:03Z"
"generated_at": "2024-10-31T21:25:32Z"
}

View File

@@ -4,7 +4,9 @@ from uuid import UUID
import pytest
from freezegun import freeze_time
from sqlalchemy import select
from app import db
from app.celery.reporting_tasks import (
create_nightly_billing,
create_nightly_billing_for_day,
@@ -132,11 +134,11 @@ def test_create_nightly_billing_for_day_checks_history(
status=NotificationStatus.DELIVERED,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 1
record = records[0]
@@ -144,6 +146,11 @@ def test_create_nightly_billing_for_day_checks_history(
assert record.notifications_sent == 2
def _get_fact_billing_records():
stmt = select(FactBilling)
return db.session.execute(stmt).scalars().all()
@pytest.mark.parametrize(
"second_rate, records_num, billable_units, multiplier",
[(1.0, 1, 2, [1]), (2.0, 2, 1, [1, 2])],
@@ -181,7 +188,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier(
billable_units=1,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))
@@ -221,7 +228,7 @@ def test_create_nightly_billing_for_day_different_templates(
billable_units=0,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))
@@ -265,7 +272,7 @@ def test_create_nightly_billing_for_day_same_sent_by(
billable_units=1,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))
@@ -296,11 +303,11 @@ def test_create_nightly_billing_for_day_null_sent_by_sms(
billable_units=1,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day(str(yesterday.date()))
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 1
record = records[0]
@@ -384,7 +391,7 @@ def test_create_nightly_billing_for_day_update_when_record_exists(
billable_units=1,
)
records = FactBilling.query.all()
records = _get_fact_billing_records()
assert len(records) == 0
create_nightly_billing_for_day("2018-01-14")

View File

@@ -4,7 +4,9 @@ from unittest import mock
import pytest
from flask import json
from sqlalchemy import func, select
from app import db
from app.enums import ServicePermissionType
from app.models import InboundSms
from app.notifications.receive_notifications import (
@@ -99,7 +101,9 @@ def test_receive_notification_from_sns_without_permissions_does_not_persist(
parsed_response = json.loads(response.get_data(as_text=True))
assert parsed_response["result"] == "success"
assert InboundSms.query.count() == 0
stmt = select(func.count()).select_from(InboundSms)
count = db.session.execute(stmt).scalar() or 0
assert count == 0
assert mocked.called is False
@@ -285,7 +289,10 @@ def test_receive_notification_error_if_not_single_matching_service(
# we still return 'RECEIVED' to MMG
assert response.status_code == 200
assert response.get_data(as_text=True) == "RECEIVED"
assert InboundSms.query.count() == 0
stmt = select(func.count()).select_from(InboundSms)
count = db.session.execute(stmt).scalar() or 0
assert count == 0
@pytest.mark.skip(reason="Need to implement inbound SNS tests. Body here from MMG")

View File

@@ -5,8 +5,10 @@ import pytest
from flask import current_app, json
from freezegun import freeze_time
from notifications_python_client.authentication import create_jwt_token
from sqlalchemy import func, select
import app
from app import db
from app.dao import notifications_dao
from app.dao.api_key_dao import save_model_api_key
from app.dao.services_dao import dao_update_service
@@ -883,7 +885,9 @@ def test_should_not_persist_notification_or_send_email_if_simulated_email(
assert response.status_code == 201
apply_async.assert_not_called()
assert Notification.query.count() == 0
stmt = select(func.count()).select_from(Notification)
count = db.session.execute(stmt).scalar() or 0
assert count == 0
@pytest.mark.parametrize("to_sms", ["+14254147755", "+14254147167"])
@@ -906,7 +910,10 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
assert response.status_code == 201
apply_async.assert_not_called()
assert Notification.query.count() == 0
stmt = select(func.count()).select_from(Notification)
count = db.session.execute(stmt).scalar() or 0
assert count == 0
@pytest.mark.parametrize("key_type", [KeyType.NORMAL, KeyType.TEAM])