mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Corrected test cases for new stats endpoints
This commit is contained in:
@@ -86,7 +86,7 @@ def fetch_notification_status_for_service_by_month(start_date, end_date, service
|
|||||||
db.session.query(
|
db.session.query(
|
||||||
func.date_trunc("month", NotificationAllTimeView.created_at).label("month"),
|
func.date_trunc("month", NotificationAllTimeView.created_at).label("month"),
|
||||||
NotificationAllTimeView.notification_type,
|
NotificationAllTimeView.notification_type,
|
||||||
NotificationAllTimeView.status.label('notification_status'),
|
NotificationAllTimeView.status.label("notification_status"),
|
||||||
func.count(NotificationAllTimeView.id).label("count"),
|
func.count(NotificationAllTimeView.id).label("count"),
|
||||||
)
|
)
|
||||||
.filter(
|
.filter(
|
||||||
|
|||||||
@@ -33,31 +33,44 @@ def test_fetch_notification_status_for_service_by_month(notify_db_session):
|
|||||||
service_1 = create_service(service_name="service_1")
|
service_1 = create_service(service_name="service_1")
|
||||||
service_2 = create_service(service_name="service_2")
|
service_2 = create_service(service_name="service_2")
|
||||||
|
|
||||||
create_ft_notification_status(
|
create_template(service=service_1)
|
||||||
date(2018, 1, 1), NotificationType.SMS, service_1, count=4
|
create_template(service=service_1, template_type=TemplateType.EMAIL)
|
||||||
)
|
# not the service being tested
|
||||||
create_ft_notification_status(
|
create_template(service=service_2)
|
||||||
date(2018, 1, 2), NotificationType.SMS, service_1, count=10
|
|
||||||
)
|
|
||||||
create_ft_notification_status(
|
|
||||||
date(2018, 1, 2),
|
|
||||||
NotificationType.SMS,
|
|
||||||
service_1,
|
|
||||||
notification_status=NotificationStatus.CREATED,
|
|
||||||
)
|
|
||||||
create_ft_notification_status(date(2018, 1, 3), NotificationType.EMAIL, service_1)
|
|
||||||
|
|
||||||
create_ft_notification_status(date(2018, 2, 2), NotificationType.SMS, service_1)
|
# loop messages for the month
|
||||||
|
for x in range(0, 14):
|
||||||
|
create_notification(
|
||||||
|
service_1.templates[0],
|
||||||
|
created_at=datetime(2018, 1, 1, 1, x, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
service_1.templates[0], created_at=datetime(2018, 1, 1, 1, 1, 0)
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
service_1.templates[1],
|
||||||
|
created_at=datetime(2018, 1, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
service_1.templates[0],
|
||||||
|
created_at=datetime(2018, 2, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
|
||||||
# not included - too early
|
# not the right month
|
||||||
create_ft_notification_status(date(2017, 12, 31), NotificationType.SMS, service_1)
|
create_notification(
|
||||||
# not included - too late
|
service_1.templates[0],
|
||||||
create_ft_notification_status(date(2017, 3, 1), NotificationType.SMS, service_1)
|
created_at=datetime(2018, 4, 1, 1, 1, 0),
|
||||||
# not included - wrong service
|
status=NotificationStatus.DELIVERED,
|
||||||
create_ft_notification_status(date(2018, 1, 3), NotificationType.SMS, service_2)
|
)
|
||||||
# not included - test keys
|
|
||||||
create_ft_notification_status(
|
# not the right service
|
||||||
date(2018, 1, 3), NotificationType.SMS, service_1, key_type=KeyType.TEST
|
create_notification(
|
||||||
|
service_2.templates[0],
|
||||||
|
created_at=datetime(2018, 2, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
|
|
||||||
results = sorted(
|
results = sorted(
|
||||||
|
|||||||
@@ -234,17 +234,36 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
|
|||||||
sms_t2 = create_template(sample_service)
|
sms_t2 = create_template(sample_service)
|
||||||
email_template = create_template(sample_service, template_type=TemplateType.EMAIL)
|
email_template = create_template(sample_service, template_type=TemplateType.EMAIL)
|
||||||
|
|
||||||
create_ft_notification_status(datetime(2016, 6, 1), template=sms_t1)
|
create_notification(
|
||||||
create_ft_notification_status(datetime(2016, 6, 2), template=sms_t1)
|
sms_t1,
|
||||||
|
created_at=datetime(2016, 6, 1, 1, 1, 0),
|
||||||
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t1)
|
status=NotificationStatus.DELIVERED,
|
||||||
create_ft_notification_status(datetime(2016, 7, 1), template=sms_t2)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 7, 1),
|
sms_t1,
|
||||||
template=sms_t1,
|
created_at=datetime(2016, 6, 2, 1, 1, 0),
|
||||||
notification_status=NotificationStatus.CREATED,
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
sms_t1,
|
||||||
|
created_at=datetime(2016, 7, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
sms_t2,
|
||||||
|
created_at=datetime(2016, 7, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
sms_t1,
|
||||||
|
created_at=datetime(2016, 7, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.CREATED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
email_template,
|
||||||
|
created_at=datetime(2016, 7, 1, 1, 1, 0),
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(datetime(2016, 7, 1), template=email_template)
|
|
||||||
|
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
"service.get_monthly_notification_stats",
|
"service.get_monthly_notification_stats",
|
||||||
@@ -275,85 +294,94 @@ def test_get_monthly_notification_stats_returns_stats(admin_request, sample_serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-06-05 12:00:00")
|
# Test removed because new endpoint uses the view which combines this data
|
||||||
def test_get_monthly_notification_stats_combines_todays_data_and_historic_stats(
|
# @freeze_time("2016-06-05 12:00:00")
|
||||||
admin_request, sample_template
|
# def test_get_monthly_notification_stats_combines_todays_data_and_historic_stats(
|
||||||
):
|
# admin_request, sample_template
|
||||||
create_ft_notification_status(
|
# ):
|
||||||
datetime(2016, 5, 1, 12),
|
# create_ft_notification_status(
|
||||||
template=sample_template,
|
# datetime(2016, 5, 1, 12),
|
||||||
count=1,
|
# template=sample_template,
|
||||||
)
|
# count=1,
|
||||||
create_ft_notification_status(
|
# )
|
||||||
datetime(2016, 6, 1, 12),
|
# create_ft_notification_status(
|
||||||
template=sample_template,
|
# datetime(2016, 6, 1, 12),
|
||||||
notification_status=NotificationStatus.CREATED,
|
# template=sample_template,
|
||||||
count=2,
|
# notification_status=NotificationStatus.CREATED,
|
||||||
) # noqa
|
# count=2,
|
||||||
|
# ) # noqa
|
||||||
|
|
||||||
create_notification(
|
# create_notification(
|
||||||
sample_template,
|
# sample_template,
|
||||||
created_at=datetime(2016, 6, 5, 12),
|
# created_at=datetime(2016, 6, 5, 12),
|
||||||
status=NotificationStatus.CREATED,
|
# status=NotificationStatus.CREATED,
|
||||||
)
|
# )
|
||||||
create_notification(
|
# create_notification(
|
||||||
sample_template,
|
# sample_template,
|
||||||
created_at=datetime(2016, 6, 5, 12),
|
# created_at=datetime(2016, 6, 5, 12),
|
||||||
status=NotificationStatus.DELIVERED,
|
# status=NotificationStatus.DELIVERED,
|
||||||
)
|
# )
|
||||||
|
|
||||||
# this doesn't get returned in the stats because it is old - it should be in ft_notification_status by now
|
# # this doesn't get returned in the stats because it is old - it should be in ft_notification_status by now
|
||||||
create_notification(
|
# create_notification(
|
||||||
sample_template,
|
# sample_template,
|
||||||
created_at=datetime(2016, 6, 4, 12),
|
# created_at=datetime(2016, 6, 4, 12),
|
||||||
status=NotificationStatus.SENDING,
|
# status=NotificationStatus.SENDING,
|
||||||
)
|
# )
|
||||||
|
|
||||||
response = admin_request.get(
|
# response = admin_request.get(
|
||||||
"service.get_monthly_notification_stats",
|
# "service.get_monthly_notification_stats",
|
||||||
service_id=sample_template.service_id,
|
# service_id=sample_template.service_id,
|
||||||
year=2016,
|
# year=2016,
|
||||||
)
|
# )
|
||||||
|
|
||||||
assert len(response["data"]) == 6 # January to June
|
# assert len(response["data"]) == 6 # January to June
|
||||||
assert response["data"]["2016-05"] == {
|
# assert response["data"]["2016-05"] == {
|
||||||
NotificationType.SMS: {
|
# NotificationType.SMS: {
|
||||||
NotificationStatus.DELIVERED: 1,
|
# NotificationStatus.DELIVERED: 1,
|
||||||
StatisticsType.REQUESTED: 1,
|
# StatisticsType.REQUESTED: 1,
|
||||||
},
|
# },
|
||||||
NotificationType.EMAIL: {},
|
# NotificationType.EMAIL: {},
|
||||||
}
|
# }
|
||||||
assert response["data"]["2016-06"] == {
|
# assert response["data"]["2016-06"] == {
|
||||||
NotificationType.SMS: {
|
# NotificationType.SMS: {
|
||||||
# combines the stats from the historic ft_notification_status and the current notifications
|
# # combines the stats from the historic ft_notification_status and the current notifications
|
||||||
NotificationStatus.CREATED: 3,
|
# NotificationStatus.CREATED: 3,
|
||||||
NotificationStatus.DELIVERED: 1,
|
# NotificationStatus.DELIVERED: 1,
|
||||||
StatisticsType.REQUESTED: 4,
|
# StatisticsType.REQUESTED: 4,
|
||||||
},
|
# },
|
||||||
NotificationType.EMAIL: {},
|
# NotificationType.EMAIL: {},
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
|
||||||
def test_get_monthly_notification_stats_ignores_test_keys(
|
def test_get_monthly_notification_stats_ignores_test_keys(
|
||||||
admin_request, sample_service
|
admin_request, sample_service
|
||||||
):
|
):
|
||||||
create_ft_notification_status(
|
create_template(service=sample_service)
|
||||||
datetime(2016, 6, 1),
|
|
||||||
service=sample_service,
|
create_notification(
|
||||||
|
sample_service.templates[0],
|
||||||
|
created_at=datetime(2016, 6, 1, 1, 1, 0),
|
||||||
key_type=KeyType.NORMAL,
|
key_type=KeyType.NORMAL,
|
||||||
count=1,
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 6, 1),
|
sample_service.templates[0],
|
||||||
service=sample_service,
|
created_at=datetime(2016, 6, 2, 1, 1, 0),
|
||||||
|
key_type=KeyType.NORMAL,
|
||||||
|
status=NotificationStatus.DELIVERED,
|
||||||
|
)
|
||||||
|
create_notification(
|
||||||
|
sample_service.templates[0],
|
||||||
|
created_at=datetime(2016, 6, 1, 1, 1, 0),
|
||||||
key_type=KeyType.TEAM,
|
key_type=KeyType.TEAM,
|
||||||
count=2,
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 6, 1),
|
sample_service.templates[0],
|
||||||
service=sample_service,
|
created_at=datetime(2016, 6, 1, 1, 1, 0),
|
||||||
key_type=KeyType.TEST,
|
key_type=KeyType.TEST,
|
||||||
count=4,
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
@@ -370,21 +398,21 @@ def test_get_monthly_notification_stats_ignores_test_keys(
|
|||||||
|
|
||||||
def test_get_monthly_notification_stats_checks_dates(admin_request, sample_service):
|
def test_get_monthly_notification_stats_checks_dates(admin_request, sample_service):
|
||||||
t = create_template(sample_service)
|
t = create_template(sample_service)
|
||||||
# create_ft_notification_status(datetime(2016, 3, 31), template=t, notification_status='created')
|
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 4, 2),
|
t,
|
||||||
template=t,
|
created_at=datetime(2016, 4, 2),
|
||||||
notification_status=NotificationStatus.SENDING,
|
status=NotificationStatus.SENDING,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2017, 3, 31),
|
t,
|
||||||
template=t,
|
created_at=datetime(2017, 3, 31),
|
||||||
notification_status=NotificationStatus.DELIVERED,
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2017, 4, 11),
|
t,
|
||||||
template=t,
|
created_at=datetime(2017, 4, 11),
|
||||||
notification_status=NotificationStatus.PERMANENT_FAILURE,
|
status=NotificationStatus.PERMANENT_FAILURE,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
@@ -411,15 +439,15 @@ def test_get_monthly_notification_stats_only_gets_for_one_service(
|
|||||||
|
|
||||||
templates = [create_template(services[0]), create_template(services[1])]
|
templates = [create_template(services[0]), create_template(services[1])]
|
||||||
|
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 6, 1),
|
templates[0],
|
||||||
template=templates[0],
|
created_at=datetime(2016, 6, 1),
|
||||||
notification_status=NotificationStatus.CREATED,
|
status=NotificationStatus.CREATED,
|
||||||
)
|
)
|
||||||
create_ft_notification_status(
|
create_notification(
|
||||||
datetime(2016, 6, 1),
|
templates[1],
|
||||||
template=templates[1],
|
created_at=datetime(2016, 6, 1),
|
||||||
notification_status=NotificationStatus.DELIVERED,
|
status=NotificationStatus.DELIVERED,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = admin_request.get(
|
response = admin_request.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user