mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-25 09:51:42 -05:00
Even more cleanup of tests.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -12,6 +12,7 @@ from app.dao.inbound_sms_dao import (
|
||||
dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service,
|
||||
delete_inbound_sms_older_than_retention,
|
||||
)
|
||||
from app.enums import NotificationType
|
||||
from app.models import InboundSmsHistory
|
||||
from tests.app.db import (
|
||||
create_inbound_sms,
|
||||
@@ -65,10 +66,10 @@ def test_get_all_inbound_sms_filters_on_service(notify_db_session):
|
||||
|
||||
def test_get_all_inbound_sms_filters_on_time(sample_service, notify_db_session):
|
||||
create_inbound_sms(
|
||||
sample_service, created_at=datetime(2017, 8, 6, 23, 59)
|
||||
sample_service, created_at=datetime(2017, 8, 6, 23, 59),
|
||||
) # sunday evening
|
||||
sms_two = create_inbound_sms(
|
||||
sample_service, created_at=datetime(2017, 8, 7, 0, 0)
|
||||
sample_service, created_at=datetime(2017, 8, 7, 0, 0),
|
||||
) # monday (7th) morning
|
||||
|
||||
with freeze_time("2017-08-14 12:00"):
|
||||
@@ -110,13 +111,13 @@ def test_should_delete_inbound_sms_according_to_data_retention(notify_db_session
|
||||
services = [short_retention_service, no_retention_service, long_retention_service]
|
||||
|
||||
create_service_data_retention(
|
||||
long_retention_service, notification_type="sms", days_of_retention=30
|
||||
long_retention_service, notification_type=NotificationType.SMS, days_of_retention=30,
|
||||
)
|
||||
create_service_data_retention(
|
||||
short_retention_service, notification_type="sms", days_of_retention=3
|
||||
short_retention_service, notification_type=NotificationType.SMS, days_of_retention=3,
|
||||
)
|
||||
create_service_data_retention(
|
||||
short_retention_service, notification_type="email", days_of_retention=4
|
||||
short_retention_service, notification_type=NotificationType.EMAIL, days_of_retention=4,
|
||||
)
|
||||
|
||||
dates = [
|
||||
|
||||
@@ -14,6 +14,7 @@ from app.dao.provider_details_dao import (
|
||||
get_provider_details_by_identifier,
|
||||
get_provider_details_by_notification_type,
|
||||
)
|
||||
from app.enums import NotificationType, TemplateType
|
||||
from app.models import ProviderDetails, ProviderDetailsHistory
|
||||
from tests.app.db import create_ft_billing, create_service, create_template
|
||||
from tests.conftest import set_config
|
||||
@@ -39,37 +40,37 @@ def set_primary_sms_provider(identifier):
|
||||
|
||||
|
||||
def test_can_get_sms_non_international_providers(notify_db_session):
|
||||
sms_providers = get_provider_details_by_notification_type("sms")
|
||||
sms_providers = get_provider_details_by_notification_type(NotificationType.SMS)
|
||||
assert len(sms_providers) > 0
|
||||
assert all("sms" == prov.notification_type for prov in sms_providers)
|
||||
assert all(NotificationType.SMS == prov.notification_type for prov in sms_providers)
|
||||
|
||||
|
||||
def test_can_get_sms_international_providers(notify_db_session):
|
||||
sms_providers = get_provider_details_by_notification_type("sms", True)
|
||||
sms_providers = get_provider_details_by_notification_type(NotificationType.SMS, True)
|
||||
assert len(sms_providers) == 1
|
||||
assert all("sms" == prov.notification_type for prov in sms_providers)
|
||||
assert all(NotificationType.SMS == prov.notification_type for prov in sms_providers)
|
||||
assert all(prov.supports_international for prov in sms_providers)
|
||||
|
||||
|
||||
def test_can_get_sms_providers_in_order_of_priority(notify_db_session):
|
||||
providers = get_provider_details_by_notification_type("sms", False)
|
||||
providers = get_provider_details_by_notification_type(NotificationType.SMS, False)
|
||||
priorities = [provider.priority for provider in providers]
|
||||
assert priorities == sorted(priorities)
|
||||
|
||||
|
||||
def test_can_get_email_providers_in_order_of_priority(notify_db_session):
|
||||
providers = get_provider_details_by_notification_type("email")
|
||||
providers = get_provider_details_by_notification_type(NotificationType.EMAIL)
|
||||
|
||||
assert providers[0].identifier == "ses"
|
||||
|
||||
|
||||
def test_can_get_email_providers(notify_db_session):
|
||||
assert len(get_provider_details_by_notification_type("email")) == 1
|
||||
assert len(get_provider_details_by_notification_type(NotificationType.EMAIL)) == 1
|
||||
types = [
|
||||
provider.notification_type
|
||||
for provider in get_provider_details_by_notification_type("email")
|
||||
for provider in get_provider_details_by_notification_type(NotificationType.EMAIL)
|
||||
]
|
||||
assert all("email" == notification_type for notification_type in types)
|
||||
assert all(NotificationType.EMAIL == notification_type for notification_type in types)
|
||||
|
||||
|
||||
def test_should_not_error_if_any_provider_in_code_not_in_database(
|
||||
@@ -222,8 +223,8 @@ def test_get_sms_providers_for_update_returns_nothing_if_recent_updates(
|
||||
def test_dao_get_provider_stats(notify_db_session):
|
||||
service_1 = create_service(service_name="1")
|
||||
service_2 = create_service(service_name="2")
|
||||
sms_template_1 = create_template(service_1, "sms")
|
||||
sms_template_2 = create_template(service_2, "sms")
|
||||
sms_template_1 = create_template(service_1, TemplateType.SMS)
|
||||
sms_template_2 = create_template(service_2, TemplateType.SMS)
|
||||
|
||||
create_ft_billing("2017-06-05", sms_template_2, provider="sns", billable_unit=4)
|
||||
create_ft_billing("2018-06-03", sms_template_2, provider="sns", billable_unit=4)
|
||||
@@ -241,7 +242,7 @@ def test_dao_get_provider_stats(notify_db_session):
|
||||
assert ses.current_month_billable_sms == 0
|
||||
|
||||
assert sns.display_name == "AWS SNS"
|
||||
assert sns.notification_type == "sms"
|
||||
assert sns.notification_type == NotificationType.SMS
|
||||
assert sns.supports_international is True
|
||||
assert sns.active is True
|
||||
assert sns.current_month_billable_sms == 5
|
||||
|
||||
@@ -11,13 +11,14 @@ from app.dao.service_data_retention_dao import (
|
||||
insert_service_data_retention,
|
||||
update_service_data_retention,
|
||||
)
|
||||
from app.enums import NotificationType
|
||||
from app.models import ServiceDataRetention
|
||||
from tests.app.db import create_service, create_service_data_retention
|
||||
|
||||
|
||||
def test_fetch_service_data_retention(sample_service):
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, "email", 3)
|
||||
sms_data_retention = insert_service_data_retention(sample_service.id, "sms", 5)
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, NotificationType.EMAIL, 3,)
|
||||
sms_data_retention = insert_service_data_retention(sample_service.id, NotificationType.SMS, 5,)
|
||||
|
||||
list_of_data_retention = fetch_service_data_retention(sample_service.id)
|
||||
|
||||
@@ -28,8 +29,8 @@ def test_fetch_service_data_retention(sample_service):
|
||||
|
||||
def test_fetch_service_data_retention_only_returns_row_for_service(sample_service):
|
||||
another_service = create_service(service_name="Another service")
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, "email", 3)
|
||||
insert_service_data_retention(another_service.id, "sms", 5)
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, NotificationType.EMAIL, 3,)
|
||||
insert_service_data_retention(another_service.id, NotificationType.SMS, 5)
|
||||
|
||||
list_of_data_retention = fetch_service_data_retention(sample_service.id)
|
||||
assert len(list_of_data_retention) == 1
|
||||
@@ -45,7 +46,7 @@ def test_fetch_service_data_retention_returns_empty_list_when_no_rows_for_servic
|
||||
|
||||
def test_fetch_service_data_retention_by_id(sample_service):
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, "email", 3)
|
||||
insert_service_data_retention(sample_service.id, "sms", 13)
|
||||
insert_service_data_retention(sample_service.id, NotificationType.SMS, 13)
|
||||
result = fetch_service_data_retention_by_id(
|
||||
sample_service.id, email_data_retention.id
|
||||
)
|
||||
@@ -61,7 +62,7 @@ def test_fetch_service_data_retention_by_id_returns_none_if_id_not_for_service(
|
||||
sample_service,
|
||||
):
|
||||
another_service = create_service(service_name="Another service")
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, "email", 3)
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, NotificationType.EMAIL, 3,)
|
||||
result = fetch_service_data_retention_by_id(
|
||||
another_service.id, email_data_retention.id
|
||||
)
|
||||
@@ -70,30 +71,30 @@ def test_fetch_service_data_retention_by_id_returns_none_if_id_not_for_service(
|
||||
|
||||
def test_insert_service_data_retention(sample_service):
|
||||
insert_service_data_retention(
|
||||
service_id=sample_service.id, notification_type="email", days_of_retention=3
|
||||
service_id=sample_service.id, notification_type=NotificationType.EMAIL, days_of_retention=3,
|
||||
)
|
||||
|
||||
results = ServiceDataRetention.query.all()
|
||||
assert len(results) == 1
|
||||
assert results[0].service_id == sample_service.id
|
||||
assert results[0].notification_type == "email"
|
||||
assert results[0].notification_type == NotificationType.EMAIL
|
||||
assert results[0].days_of_retention == 3
|
||||
assert results[0].created_at.date() == datetime.utcnow().date()
|
||||
|
||||
|
||||
def test_insert_service_data_retention_throws_unique_constraint(sample_service):
|
||||
insert_service_data_retention(
|
||||
service_id=sample_service.id, notification_type="email", days_of_retention=3
|
||||
service_id=sample_service.id, notification_type=NotificationType.EMAIL, days_of_retention=3,
|
||||
)
|
||||
with pytest.raises(expected_exception=IntegrityError):
|
||||
insert_service_data_retention(
|
||||
service_id=sample_service.id, notification_type="email", days_of_retention=5
|
||||
service_id=sample_service.id, notification_type=NotificationType.EMAIL, days_of_retention=5,
|
||||
)
|
||||
|
||||
|
||||
def test_update_service_data_retention(sample_service):
|
||||
data_retention = insert_service_data_retention(
|
||||
service_id=sample_service.id, notification_type="sms", days_of_retention=3
|
||||
service_id=sample_service.id, notification_type=NotificationType.SMS, days_of_retention=3
|
||||
)
|
||||
updated_count = update_service_data_retention(
|
||||
service_data_retention_id=data_retention.id,
|
||||
@@ -105,7 +106,7 @@ def test_update_service_data_retention(sample_service):
|
||||
assert len(results) == 1
|
||||
assert results[0].id == data_retention.id
|
||||
assert results[0].service_id == sample_service.id
|
||||
assert results[0].notification_type == "sms"
|
||||
assert results[0].notification_type == NotificationType.SMS
|
||||
assert results[0].days_of_retention == 5
|
||||
assert results[0].created_at.date() == datetime.utcnow().date()
|
||||
assert results[0].updated_at.date() == datetime.utcnow().date()
|
||||
@@ -127,7 +128,7 @@ def test_update_service_data_retention_does_not_update_row_if_data_retention_is_
|
||||
sample_service,
|
||||
):
|
||||
data_retention = insert_service_data_retention(
|
||||
service_id=sample_service.id, notification_type="email", days_of_retention=3
|
||||
service_id=sample_service.id, notification_type=NotificationType.EMAIL, days_of_retention=3,
|
||||
)
|
||||
updated_count = update_service_data_retention(
|
||||
service_data_retention_id=data_retention.id,
|
||||
@@ -138,7 +139,7 @@ def test_update_service_data_retention_does_not_update_row_if_data_retention_is_
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"notification_type, alternate", [("sms", "email"), ("email", "sms")]
|
||||
"notification_type, alternate", [(NotificationType.SMS, NotificationType.EMAIL), (NotificationType.EMAIL, NotificationType.SMS),],
|
||||
)
|
||||
def test_fetch_service_data_retention_by_notification_type(
|
||||
sample_service, notification_type, alternate
|
||||
@@ -157,5 +158,5 @@ def test_fetch_service_data_retention_by_notification_type_returns_none_when_no_
|
||||
sample_service,
|
||||
):
|
||||
assert not fetch_service_data_retention_by_notification_type(
|
||||
sample_service.id, "email"
|
||||
sample_service.id, NotificationType.EMAIL,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user