mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Merge branch 'master' into remove-stats-from-send
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
import copy
|
||||
from flask import url_for
|
||||
|
||||
@@ -5,7 +6,7 @@ import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.main.views.dashboard import get_dashboard_totals
|
||||
from app.main.views.dashboard import get_dashboard_totals, format_weekly_stats_to_list
|
||||
|
||||
from tests import validate_route_permission
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
@@ -65,7 +66,6 @@ def test_get_started(
|
||||
api_user_active,
|
||||
mock_get_service,
|
||||
mock_get_service_templates_when_no_templates_exist,
|
||||
mock_get_aggregate_service_statistics,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_login,
|
||||
@@ -94,7 +94,6 @@ def test_get_started_is_hidden_once_templates_exist(
|
||||
api_user_active,
|
||||
mock_get_service,
|
||||
mock_get_service_templates,
|
||||
mock_get_aggregate_service_statistics,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_login,
|
||||
@@ -119,7 +118,6 @@ def test_should_show_recent_templates_on_dashboard(app_,
|
||||
api_user_active,
|
||||
mock_get_service,
|
||||
mock_get_service_templates,
|
||||
mock_get_aggregate_service_statistics,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_login,
|
||||
@@ -204,7 +202,6 @@ def test_should_show_recent_jobs_on_dashboard(
|
||||
api_user_active,
|
||||
mock_get_service,
|
||||
mock_get_service_templates,
|
||||
mock_get_aggregate_service_statistics,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_login,
|
||||
@@ -482,3 +479,46 @@ def test_get_dashboard_totals_adds_warning(failures, expected):
|
||||
}
|
||||
}
|
||||
assert get_dashboard_totals(stats)['sms']['show_warning'] == expected
|
||||
|
||||
|
||||
def test_format_weekly_stats_to_list_empty_case():
|
||||
assert format_weekly_stats_to_list({}) == []
|
||||
|
||||
|
||||
def test_format_weekly_stats_to_list_sorts_by_week():
|
||||
stats = {
|
||||
'2016-07-04': {},
|
||||
'2016-07-11': {},
|
||||
'2016-07-18': {},
|
||||
'2016-07-25': {}
|
||||
}
|
||||
resp = format_weekly_stats_to_list(stats)
|
||||
assert resp[0]['week_start'] == '2016-07-25'
|
||||
assert resp[1]['week_start'] == '2016-07-18'
|
||||
assert resp[2]['week_start'] == '2016-07-11'
|
||||
assert resp[3]['week_start'] == '2016-07-04'
|
||||
|
||||
|
||||
def test_format_weekly_stats_to_list_includes_datetime_for_comparison():
|
||||
stats = {
|
||||
'2016-07-25': {}
|
||||
}
|
||||
resp = format_weekly_stats_to_list(stats)
|
||||
assert resp == [{
|
||||
'week_start': '2016-07-25',
|
||||
'week_end': '2016-07-31',
|
||||
'week_end_datetime': datetime(2016, 7, 31, 0, 0, 0)
|
||||
}]
|
||||
|
||||
|
||||
def test_format_weekly_stats_to_list_has_stats_with_failure_rate():
|
||||
stats = {
|
||||
'2016-07-25': {'sms': _stats(3, 1, 2)}
|
||||
}
|
||||
resp = format_weekly_stats_to_list(stats)
|
||||
assert resp[0]['sms']['failure_rate'] == '66.7'
|
||||
assert resp[0]['sms']['requested'] == 3
|
||||
|
||||
|
||||
def _stats(requested, delivered, failed):
|
||||
return {'requested': requested, 'delivered': delivered, 'failed': failed}
|
||||
|
||||
@@ -26,17 +26,27 @@ def test_get_feedback_page(app_):
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
||||
def test_post_feedback_with_name_but_no_email(app_, mocker):
|
||||
mock_post = mocker.patch(
|
||||
'app.main.views.feedback.requests.post',
|
||||
return_value=Mock(status_code=201))
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
resp = client.post(url_for('main.feedback'), data={'feedback': "blah"})
|
||||
resp = client.post(url_for('main.feedback'), data={'feedback': "blah", 'name': 'Fred'})
|
||||
assert resp.status_code == 302
|
||||
mock_post.assert_called_with(
|
||||
ANY,
|
||||
data={
|
||||
'department_id': ANY,
|
||||
'agent_team_id': ANY,
|
||||
'subject': 'Notify feedback',
|
||||
'message': 'Environment: http://localhost/\nFred (no email address supplied)\nblah',
|
||||
'person_email': app_.config['DESKPRO_PERSON_EMAIL'],
|
||||
'person_name': 'Fred'},
|
||||
headers=ANY)
|
||||
|
||||
|
||||
def test_post_feedback_with_no_name_email(app_, mocker):
|
||||
def test_post_feedback_with_no_name_or_email(app_, mocker):
|
||||
mock_post = mocker.patch(
|
||||
'app.main.views.feedback.requests.post',
|
||||
return_value=Mock(status_code=201))
|
||||
@@ -50,8 +60,9 @@ def test_post_feedback_with_no_name_email(app_, mocker):
|
||||
'department_id': ANY,
|
||||
'agent_team_id': ANY,
|
||||
'subject': 'Notify feedback',
|
||||
'message': 'Environment: http://localhost/\n\n\n\nblah',
|
||||
'person_email': ANY},
|
||||
'message': 'Environment: http://localhost/\n (no email address supplied)\nblah',
|
||||
'person_email': app_.config['DESKPRO_PERSON_EMAIL'],
|
||||
'person_name': None},
|
||||
headers=ANY)
|
||||
|
||||
|
||||
@@ -71,8 +82,9 @@ def test_post_feedback_with_name_email(app_, mocker):
|
||||
'subject': 'Notify feedback',
|
||||
'department_id': ANY,
|
||||
'agent_team_id': ANY,
|
||||
'message': 'Environment: http://localhost/\n\nSteve Irwin\nrip@gmail.com\nblah',
|
||||
'person_email': ANY},
|
||||
'message': 'Environment: http://localhost/\n\nblah',
|
||||
'person_name': 'Steve Irwin',
|
||||
'person_email': 'rip@gmail.com'},
|
||||
headers=ANY)
|
||||
|
||||
|
||||
@@ -91,14 +103,6 @@ def test_log_error_on_post(app_, mocker):
|
||||
resp = client.post(
|
||||
url_for('main.feedback'),
|
||||
data={'feedback': "blah", 'name': "Steve Irwin", 'email_address': 'rip@gmail.com'})
|
||||
mock_post.assert_called_with(
|
||||
ANY,
|
||||
data={
|
||||
'subject': 'Notify feedback',
|
||||
'department_id': ANY,
|
||||
'agent_team_id': ANY,
|
||||
'message': 'Environment: http://localhost/\n\nSteve Irwin\nrip@gmail.com\nblah',
|
||||
'person_email': ANY},
|
||||
headers=ANY)
|
||||
assert mock_post.called
|
||||
mock_logger.assert_called_with(
|
||||
"Deskpro create ticket request failed with {} '{}'".format(mock_post().status_code, mock_post().json()))
|
||||
|
||||
@@ -32,15 +32,11 @@ def test_should_return_list_of_all_jobs(app_,
|
||||
"status_argument, expected_api_call", [
|
||||
(
|
||||
'',
|
||||
['sending', 'delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
|
||||
),
|
||||
(
|
||||
'processed',
|
||||
['sending', 'delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
|
||||
['created', 'sending', 'delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
|
||||
),
|
||||
(
|
||||
'sending',
|
||||
['sending']
|
||||
['sending', 'created']
|
||||
),
|
||||
(
|
||||
'delivered',
|
||||
@@ -99,6 +95,7 @@ def test_should_show_page_for_one_job(
|
||||
)
|
||||
assert csv_link.text == 'Download this report'
|
||||
assert page.find('span', {'id': 'time-left'}).text == 'Data available for 7 days'
|
||||
assert page.find('p', {'class': 'table-show-more-link'}).text.strip() == 'Only showing the first 50 rows'
|
||||
mock_get_notifications.assert_called_with(
|
||||
service_one['id'],
|
||||
fake_uuid,
|
||||
@@ -106,6 +103,29 @@ def test_should_show_page_for_one_job(
|
||||
)
|
||||
|
||||
|
||||
def test_should_show_job_in_progress(
|
||||
app_,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_template,
|
||||
mock_get_job_in_progress,
|
||||
mocker,
|
||||
mock_get_notifications,
|
||||
fake_uuid
|
||||
):
|
||||
with app_.test_request_context(), app_.test_client() as client:
|
||||
client.login(active_user_with_permissions, mocker, service_one)
|
||||
response = client.get(url_for(
|
||||
'main.view_job',
|
||||
service_id=service_one['id'],
|
||||
job_id=fake_uuid
|
||||
))
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find('p', {'class': 'hint'}).text.strip() == 'Report is 50% complete…'
|
||||
|
||||
|
||||
def test_should_show_not_show_csv_download_in_tour(
|
||||
app_,
|
||||
service_one,
|
||||
@@ -179,12 +199,12 @@ def test_should_show_updates_for_one_job_as_json(
|
||||
@pytest.mark.parametrize(
|
||||
"status_argument, expected_api_call", [
|
||||
(
|
||||
'processed',
|
||||
['sending', 'delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
|
||||
'',
|
||||
['created', 'sending', 'delivered', 'failed', 'temporary-failure', 'permanent-failure', 'technical-failure']
|
||||
),
|
||||
(
|
||||
'sending',
|
||||
['sending']
|
||||
['sending', 'created']
|
||||
),
|
||||
(
|
||||
'delivered',
|
||||
@@ -275,10 +295,21 @@ def test_should_show_notifications_for_a_service_with_next_previous(
|
||||
))
|
||||
assert response.status_code == 200
|
||||
content = response.get_data(as_text=True)
|
||||
assert url_for('main.view_notifications', service_id=service_one['id'], message_type='sms', page=3) in content
|
||||
assert url_for('main.view_notifications', service_id=service_one['id'], message_type='sms', page=1) in content
|
||||
assert 'Previous page' in content
|
||||
assert 'Next page' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
next_page_link = page.find('a', {'rel': 'next'})
|
||||
prev_page_link = page.find('a', {'rel': 'previous'})
|
||||
assert (
|
||||
url_for('main.view_notifications', service_id=service_one['id'], message_type='sms', page=3) in
|
||||
next_page_link['href']
|
||||
)
|
||||
assert 'Next page' in next_page_link.text.strip()
|
||||
assert 'page 3' in next_page_link.text.strip()
|
||||
assert (
|
||||
url_for('main.view_notifications', service_id=service_one['id'], message_type='sms', page=1) in
|
||||
prev_page_link['href']
|
||||
)
|
||||
assert 'Previous page' in prev_page_link.text.strip()
|
||||
assert 'page 1' in prev_page_link.text.strip()
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
@@ -335,7 +366,7 @@ def test_get_status_filters_calculates_stats(app_):
|
||||
ret = get_status_filters({'id': 'foo'}, 'sms', STATISTICS)
|
||||
|
||||
assert {label: count for label, _option, _link, count in ret} == {
|
||||
'processed': 6,
|
||||
'total': 6,
|
||||
'sending': 3,
|
||||
'failed': 2,
|
||||
'delivered': 1
|
||||
@@ -347,7 +378,7 @@ def test_get_status_filters_in_right_order(app_):
|
||||
ret = get_status_filters({'id': 'foo'}, 'sms', STATISTICS)
|
||||
|
||||
assert [label for label, _option, _link, _count in ret] == [
|
||||
'processed', 'sending', 'delivered', 'failed'
|
||||
'total', 'sending', 'delivered', 'failed'
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -241,10 +241,9 @@ def test_should_redirect_after_request_to_go_live(
|
||||
'subject': 'Request to go live',
|
||||
'department_id': ANY,
|
||||
'agent_team_id': ANY,
|
||||
'message': 'From Test User <test@user.gov.uk> on behalf of Test Service (http://localhost/services/6ce466d0-fd6a-11e5-82f5-e0accb9d11a6/dashboard)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
||||
# noqa
|
||||
# noqa
|
||||
'person_email': ANY
|
||||
'message': 'On behalf of Test Service (http://localhost/services/6ce466d0-fd6a-11e5-82f5-e0accb9d11a6/dashboard)\n\nUsage estimate\n---\n\nOne million messages', # noqa
|
||||
'person_name': api_user_active.name,
|
||||
'person_email': api_user_active.email_address
|
||||
},
|
||||
headers=ANY
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user