mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-19 05:54:18 -04:00
Merge branch 'master' of https://github.com/alphagov/notifications-api into add-reply-to-notifications
This commit is contained in:
@@ -25,7 +25,6 @@ from app.dao.services_dao import (
|
||||
dao_fetch_stats_for_service,
|
||||
dao_fetch_todays_stats_for_service,
|
||||
dao_fetch_monthly_historical_stats_for_service,
|
||||
dao_fetch_monthly_historical_stats_by_template_for_service,
|
||||
fetch_todays_total_message_count,
|
||||
dao_fetch_todays_stats_for_all_services,
|
||||
fetch_stats_by_date_range_for_all_services,
|
||||
@@ -77,7 +76,6 @@ from tests.app.conftest import (
|
||||
|
||||
|
||||
def test_should_have_decorated_services_dao_functions():
|
||||
assert dao_fetch_monthly_historical_stats_by_template_for_service.__wrapped__.__name__ == 'dao_fetch_monthly_historical_stats_by_template_for_service' # noqa
|
||||
assert dao_fetch_monthly_historical_stats_for_service.__wrapped__.__name__ == 'dao_fetch_monthly_historical_stats_for_service' # noqa
|
||||
assert dao_fetch_todays_stats_for_service.__wrapped__.__name__ == 'dao_fetch_todays_stats_for_service' # noqa
|
||||
assert dao_fetch_stats_for_service.__wrapped__.__name__ == 'dao_fetch_stats_for_service' # noqa
|
||||
@@ -850,93 +848,6 @@ def test_dao_resume_service_marks_service_as_active_and_api_keys_are_still_revok
|
||||
assert api_key.expiry_date == datetime(2001, 1, 1, 23, 59, 00)
|
||||
|
||||
|
||||
def test_fetch_monthly_historical_template_stats_for_service_includes_financial_year_only(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
)
|
||||
|
||||
notification_history(created_at=datetime(2016, 4, 1), status='sending') # Start of financial year
|
||||
notification_history(created_at=datetime(2016, 5, 30), status='created')
|
||||
notification_history(created_at=datetime(2016, 6, 1), status='created')
|
||||
notification_history(created_at=datetime(2017, 3, 31), status='created') # End of financial year
|
||||
notification_history(created_at=datetime(2017, 4, 1), status='created')
|
||||
notification_history(created_at=datetime(2017, 5, 1), status='created')
|
||||
|
||||
result = dao_fetch_monthly_historical_stats_by_template_for_service(sample_template.service_id, 2016)
|
||||
|
||||
notifications_count = 0
|
||||
for dict in result.values():
|
||||
notifications_count += sum(dict.get(str(sample_template.id), {}).get("counts", {}).values())
|
||||
|
||||
assert '2017-04' not in result
|
||||
assert '2017-05' not in result
|
||||
assert notifications_count == 4
|
||||
|
||||
|
||||
def test_fetch_monthly_historical_template_stats_for_service_separates_months(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
)
|
||||
|
||||
notification_history(created_at=datetime(2016, 4, 1), status='sending') # Start of financial year
|
||||
notification_history(created_at=datetime(2016, 5, 30), status='created')
|
||||
notification_history(created_at=datetime(2016, 6, 1), status='delivered')
|
||||
notification_history(created_at=datetime(2016, 6, 1), status='created')
|
||||
notification_history(created_at=datetime(2016, 12, 1), status='created')
|
||||
notification_history(created_at=datetime(2017, 3, 30), status='sending')
|
||||
notification_history(created_at=datetime(2017, 3, 31), status='sending')
|
||||
|
||||
result = dao_fetch_monthly_historical_stats_by_template_for_service(sample_template.service_id, 2016)
|
||||
|
||||
financial_year_month_keys = \
|
||||
['2016-{:02}'.format(month) for month in range(4, 13)] + ['2017-{:02}'.format(month) for month in range(1, 4)]
|
||||
|
||||
assert set(financial_year_month_keys) == set(result.keys())
|
||||
assert sum(result["2016-04"][str(sample_template.id)]["counts"].values()) == 1
|
||||
assert sum(result["2016-05"][str(sample_template.id)]["counts"].values()) == 1
|
||||
assert sum(result["2016-06"][str(sample_template.id)]["counts"].values()) == 2
|
||||
assert sum(result["2016-12"][str(sample_template.id)]["counts"].values()) == 1
|
||||
assert sum(result["2017-03"][str(sample_template.id)]["counts"].values()) == 2
|
||||
|
||||
|
||||
def test_fetch_monthly_historical_template_stats_for_service_separates_templates(
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
template_one = create_sample_template(notify_db, notify_db_session)
|
||||
template_two = create_sample_template(notify_db, notify_db_session)
|
||||
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_one)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
|
||||
result = dao_fetch_monthly_historical_stats_by_template_for_service(template_one.service_id, 2016)
|
||||
|
||||
assert len(result.get('2016-04').keys()) == 2
|
||||
assert str(template_one.id) in result.get('2016-04').keys()
|
||||
assert str(template_two.id) in result.get('2016-04').keys()
|
||||
|
||||
|
||||
def test_dao_fetch_active_users_for_service_returns_active_only(notify_db, notify_db_session):
|
||||
active_user = create_user(email='active@foo.com', state='active')
|
||||
pending_user = create_user(email='pending@foo.com', state='pending')
|
||||
|
||||
@@ -400,7 +400,6 @@ def test_strip_leading_country_code(number, expected):
|
||||
["", [], 401],
|
||||
["testkey", [], 403],
|
||||
])
|
||||
@pytest.mark.skip(reason="aborts are disabled at the moment")
|
||||
def test_firetext_inbound_sms_auth(notify_db_session, notify_api, client, mocker, auth, keys, status_code):
|
||||
mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
|
||||
|
||||
|
||||
@@ -1810,33 +1810,6 @@ def test_get_service_provider_aggregate_statistics(
|
||||
assert json.loads(response.get_data(as_text=True)) == expected_json
|
||||
|
||||
|
||||
def test_get_template_stats_by_month_returns_correct_data(notify_db, notify_db_session, client, sample_template):
|
||||
notification_history = partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template
|
||||
)
|
||||
with freeze_time('2016-05-01T12:00:00'):
|
||||
not1 = notification_history(status='sending')
|
||||
notification_history(status='sending')
|
||||
notification_history(status='permanent-failure')
|
||||
notification_history(status='temporary-failure')
|
||||
|
||||
resp = client.get(
|
||||
'/service/{}/notifications/templates/monthly?year=2016'.format(not1.service_id),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
resp_json = json.loads(resp.get_data(as_text=True)).get('data')
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp_json["2016-05"][str(sample_template.id)]["name"] == "Template Name"
|
||||
assert resp_json["2016-05"][str(sample_template.id)]["type"] == "sms"
|
||||
assert resp_json["2016-05"][str(sample_template.id)]["counts"]["sending"] == 2
|
||||
assert resp_json["2016-05"][str(sample_template.id)]["counts"]["temporary-failure"] == 1
|
||||
assert resp_json["2016-05"][str(sample_template.id)]["counts"]["permanent-failure"] == 1
|
||||
|
||||
|
||||
@freeze_time('2017-11-11 02:00')
|
||||
def test_get_template_usage_by_month_returns_correct_data(
|
||||
notify_db,
|
||||
@@ -2048,24 +2021,6 @@ def test_get_template_usage_by_month_returns_two_templates(
|
||||
assert resp_json[2]["count"] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize('query_string, expected_status, expected_json', [
|
||||
('?year=abcd', 400, {'message': 'Year must be a number', 'result': 'error'}),
|
||||
])
|
||||
def test_get_template_stats_by_month_returns_error_for_incorrect_year(
|
||||
client,
|
||||
sample_service,
|
||||
query_string,
|
||||
expected_status,
|
||||
expected_json
|
||||
):
|
||||
response = client.get(
|
||||
'/service/{}/notifications/templates/monthly{}'.format(sample_service.id, query_string),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
assert response.status_code == expected_status
|
||||
assert json.loads(response.get_data(as_text=True)) == expected_json
|
||||
|
||||
|
||||
def test_search_for_notification_by_to_field(client, notify_db, notify_db_session):
|
||||
create_notification = partial(create_sample_notification, notify_db, notify_db_session)
|
||||
notification1 = create_notification(to_field='+447700900855', normalised_to='447700900855')
|
||||
|
||||
Reference in New Issue
Block a user