2016-08-18 14:01:31 +01:00
|
|
|
from datetime import datetime, timedelta
|
2018-04-12 10:46:22 +01:00
|
|
|
import uuid
|
2016-06-07 14:18:42 +01:00
|
|
|
|
2017-02-13 18:47:29 +00:00
|
|
|
import pytest
|
2016-04-04 12:21:38 +01:00
|
|
|
from freezegun import freeze_time
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
from tests.app.conftest import sample_notification
|
2017-11-10 11:33:42 +00:00
|
|
|
|
2016-08-18 14:01:31 +01:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
# get_template_statistics_for_service_by_day
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('query_string', [
|
|
|
|
|
{},
|
|
|
|
|
{'limit_days': 0},
|
|
|
|
|
{'limit_days': 8},
|
|
|
|
|
{'limit_days': 3.5},
|
|
|
|
|
{'limit_days': 'blurk'},
|
|
|
|
|
])
|
|
|
|
|
def get_template_statistics_for_service_by_day_with_bad_arg_returns_400(admin_request, query_string):
|
|
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_service_by_day',
|
|
|
|
|
service_id=uuid.uuid4(),
|
|
|
|
|
**query_string,
|
|
|
|
|
_expected_status=400
|
|
|
|
|
)
|
|
|
|
|
assert json_resp['result'] == 'error'
|
|
|
|
|
assert 'limit_days' in json_resp['message']
|
2016-08-18 14:01:31 +01:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_service_by_day_returns_template_info(admin_request, mocker, sample_notification):
|
|
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_service_by_day',
|
|
|
|
|
service_id=sample_notification.service_id,
|
|
|
|
|
limit_days=1
|
2017-02-13 18:47:29 +00:00
|
|
|
)
|
2016-08-18 14:01:31 +01:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
assert len(json_resp) == 1
|
2016-08-18 14:01:31 +01:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
assert json_resp['data'][0]['count'] == 1
|
|
|
|
|
assert json_resp['data'][0]['template_id'] == str(sample_notification.template_id)
|
|
|
|
|
assert json_resp['data'][0]['template_name'] == 'Template Name'
|
|
|
|
|
assert json_resp['data'][0]['template_type'] == 'sms'
|
2016-08-18 14:01:31 +01:00
|
|
|
|
2017-02-13 18:47:29 +00:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_service_by_day_gets_out_of_redis_if_available(admin_request, mocker):
|
|
|
|
|
assert False
|
2017-02-13 18:47:29 +00:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_service_by_day_goes_to_db_if_not_in_redis(admin_request, mocker):
|
|
|
|
|
assert False
|
2017-02-13 18:47:29 +00:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_service_by_day_gets_stats_for_correct_days(admin_request, mocker):
|
|
|
|
|
assert False
|
2017-02-13 18:47:29 +00:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_service_by_day_returns_empty_list_if_no_templates(
|
|
|
|
|
admin_request,
|
|
|
|
|
mocker,
|
|
|
|
|
sample_service
|
|
|
|
|
):
|
|
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_service_by_day',
|
|
|
|
|
service_id=sample_service.id,
|
|
|
|
|
limit_days=1
|
2017-02-13 18:47:29 +00:00
|
|
|
)
|
2016-08-18 14:01:31 +01:00
|
|
|
|
2017-02-13 18:47:29 +00:00
|
|
|
assert len(json_resp['data']) == 0
|
2018-04-12 10:46:22 +01:00
|
|
|
|
|
|
|
|
# get_template_statistics_for_template
|
2016-04-04 12:21:38 +01:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_template_returns_last_notification(
|
2016-06-07 14:18:42 +01:00
|
|
|
notify_db,
|
|
|
|
|
notify_db_session,
|
2018-04-12 10:46:22 +01:00
|
|
|
admin_request):
|
2017-02-13 18:47:29 +00:00
|
|
|
sample_notification(notify_db, notify_db_session)
|
|
|
|
|
sample_notification(notify_db, notify_db_session)
|
|
|
|
|
notification_3 = sample_notification(notify_db, notify_db_session)
|
2016-08-22 14:35:04 +01:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_template_id',
|
|
|
|
|
service_id=notification_3.service_id,
|
|
|
|
|
template_id=notification_3.template_id
|
2017-02-13 18:47:29 +00:00
|
|
|
)
|
2016-06-07 14:18:42 +01:00
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
assert json_resp['data']['id'] == str(notification_3.id)
|
2016-06-07 14:18:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_template_statistics_for_template_returns_empty_if_no_statistics(
|
2018-04-12 10:46:22 +01:00
|
|
|
admin_request,
|
2017-07-26 12:09:13 +01:00
|
|
|
sample_template,
|
2016-06-07 14:18:42 +01:00
|
|
|
):
|
2018-04-12 10:46:22 +01:00
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_template_id',
|
|
|
|
|
service_id=sample_template.service_id,
|
|
|
|
|
template_id=sample_template.id
|
2017-02-13 18:47:29 +00:00
|
|
|
)
|
2016-06-07 14:18:42 +01:00
|
|
|
|
2017-08-07 10:23:20 +01:00
|
|
|
assert not json_resp['data']
|
2017-07-26 12:09:13 +01:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_template_raises_error_for_nonexistent_template(
|
|
|
|
|
admin_request,
|
2017-07-26 12:09:13 +01:00
|
|
|
sample_service,
|
|
|
|
|
fake_uuid
|
|
|
|
|
):
|
2018-04-12 10:46:22 +01:00
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_template_id',
|
|
|
|
|
service_id=sample_service.id,
|
|
|
|
|
template_id=fake_uuid,
|
|
|
|
|
_expected_status=404
|
2017-07-26 12:09:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_resp['message'] == 'No result found'
|
2017-02-13 18:47:29 +00:00
|
|
|
assert json_resp['result'] == 'error'
|
2017-08-07 10:23:20 +01:00
|
|
|
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
def test_get_template_statistics_for_template_returns_empty_for_old_notification(
|
|
|
|
|
admin_request,
|
|
|
|
|
sample_notification_history
|
2017-08-07 10:23:20 +01:00
|
|
|
):
|
2018-04-12 10:46:22 +01:00
|
|
|
json_resp = admin_request.get(
|
|
|
|
|
'template_statistics.get_template_statistics_for_template_id',
|
|
|
|
|
service_id=sample_notification_history.service_id,
|
|
|
|
|
template_id=sample_notification_history.template_id
|
2017-08-07 10:23:20 +01:00
|
|
|
)
|
|
|
|
|
|
2018-04-12 10:46:22 +01:00
|
|
|
assert not json_resp['data']
|