mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-28 19:59:47 -04:00
Merge pull request #804 from alphagov/feat-add-perf-platform-client-and-job
Add client and job to update the performance platform daily
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from datetime import datetime, timedelta, date
|
||||
import pytz
|
||||
import uuid
|
||||
from functools import partial
|
||||
|
||||
@@ -35,6 +34,7 @@ from app.dao.notifications_dao import (
|
||||
get_notification_with_personalisation,
|
||||
get_notifications_for_job,
|
||||
get_notifications_for_service,
|
||||
get_total_sent_notifications_in_date_range,
|
||||
update_notification_status_by_id,
|
||||
update_notification_status_by_reference,
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
@@ -43,9 +43,15 @@ from app.dao.notifications_dao import (
|
||||
get_april_fools)
|
||||
|
||||
from app.dao.services_dao import dao_update_service
|
||||
|
||||
from tests.app.conftest import (sample_notification, sample_template, sample_email_template, sample_service, sample_job,
|
||||
sample_api_key)
|
||||
from tests.app.conftest import (
|
||||
sample_notification,
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
sample_service,
|
||||
sample_job,
|
||||
sample_api_key,
|
||||
sample_notification_history as create_notification_history
|
||||
)
|
||||
|
||||
|
||||
def test_should_have_decorated_notifications_dao_functions():
|
||||
@@ -1306,3 +1312,113 @@ def test_get_april_fools():
|
||||
april_fools = get_april_fools(2016)
|
||||
assert str(april_fools) == '2016-03-31 23:00:00'
|
||||
assert april_fools.tzinfo is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('notification_type', ['sms', 'email'])
|
||||
def test_get_total_sent_notifications_in_date_range_returns_only_in_date_range(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
notification_type
|
||||
):
|
||||
notification_history = partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
notification_type=notification_type,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
start_date = datetime(2000, 3, 30, 0, 0, 0, 0)
|
||||
with freeze_time(start_date):
|
||||
notification_history(created_at=start_date + timedelta(hours=3))
|
||||
notification_history(created_at=start_date + timedelta(hours=5, minutes=10))
|
||||
notification_history(created_at=start_date + timedelta(hours=11, minutes=59))
|
||||
|
||||
end_date = datetime(2000, 3, 31, 0, 0, 0, 0)
|
||||
notification_history(created_at=end_date + timedelta(seconds=1))
|
||||
notification_history(created_at=end_date + timedelta(minutes=10))
|
||||
|
||||
total_count = get_total_sent_notifications_in_date_range(start_date, end_date, notification_type)
|
||||
assert total_count == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize('notification_type', ['sms', 'email'])
|
||||
def test_get_total_sent_notifications_in_date_range_excludes_test_key_notifications(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
notification_type
|
||||
):
|
||||
notification_history = partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
notification_type=notification_type,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
start_date = datetime(2000, 3, 30, 0, 0, 0, 0)
|
||||
end_date = datetime(2000, 3, 31, 0, 0, 0, 0)
|
||||
with freeze_time(start_date):
|
||||
notification_history(key_type=KEY_TYPE_TEAM)
|
||||
notification_history(key_type=KEY_TYPE_TEAM)
|
||||
notification_history(key_type=KEY_TYPE_NORMAL)
|
||||
notification_history(key_type=KEY_TYPE_TEST)
|
||||
|
||||
total_count = get_total_sent_notifications_in_date_range(start_date, end_date, notification_type)
|
||||
assert total_count == 3
|
||||
|
||||
|
||||
def test_get_total_sent_notifications_for_sms_excludes_email_counts(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
notification_history = partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
start_date = datetime(2000, 3, 30, 0, 0, 0, 0)
|
||||
end_date = datetime(2000, 3, 31, 0, 0, 0, 0)
|
||||
with freeze_time(start_date):
|
||||
notification_history(notification_type='email')
|
||||
notification_history(notification_type='email')
|
||||
notification_history(notification_type='sms')
|
||||
notification_history(notification_type='sms')
|
||||
notification_history(notification_type='sms')
|
||||
|
||||
total_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'sms')
|
||||
assert total_count == 3
|
||||
|
||||
|
||||
def test_get_total_sent_notifications_for_email_excludes_sms_counts(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
notification_history = partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
start_date = datetime(2000, 3, 30, 0, 0, 0, 0)
|
||||
end_date = datetime(2000, 3, 31, 0, 0, 0, 0)
|
||||
with freeze_time(start_date):
|
||||
notification_history(notification_type='email')
|
||||
notification_history(notification_type='email')
|
||||
notification_history(notification_type='sms')
|
||||
notification_history(notification_type='sms')
|
||||
notification_history(notification_type='sms')
|
||||
|
||||
total_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'email')
|
||||
assert total_count == 2
|
||||
|
||||
Reference in New Issue
Block a user