Revert "Merge pull request #1328 from alphagov/notification-page-reworked"

This reverts commit 1797162248, reversing
changes made to 95b4d9eb31.
This commit is contained in:
Chris Hill-Scott
2017-06-23 15:56:25 +01:00
parent 5c0f6796e4
commit b450a349a3
21 changed files with 195 additions and 182 deletions

View File

@@ -107,8 +107,6 @@ def template_json(service_id,
'archived': archived,
'process_type': process_type
}
if subject is None and type_ != 'sms':
template['subject'] = "template subject"
if subject is not None:
template['subject'] = subject
return template
@@ -186,7 +184,7 @@ def job_json(
if job_id is None:
job_id = str(generate_uuid())
if template_id is None:
template_id = "5d729fbd-239c-44ab-b498-75a985f3198f"
template_id = str(generate_uuid())
if created_at is None:
created_at = str(datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%f%z'))
data = {
@@ -222,8 +220,7 @@ def notification_json(
created_at=None,
updated_at=None,
with_links=False,
rows=5,
personalisation=None,
rows=5
):
if template is None:
template = template_json(service_id, str(generate_uuid()))
@@ -262,8 +259,7 @@ def notification_json(
'updated_at': updated_at,
'job_row_number': job_row_number,
'service': service_id,
'template_version': template['version'],
'personalisation': personalisation or {},
'template_version': template['version']
} for i in range(rows)],
'total': rows,
'page_size': 50,

View File

@@ -92,17 +92,13 @@ def test_can_show_notifications(
page=page_argument,
))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
content = response.get_data(as_text=True)
notifications = notification_json(service_one['id'])
notification = notifications['notifications'][0]
text_of_first_row = page.select('tbody tr')[0].text
assert '07123456789' in text_of_first_row
assert (
'template content' in text_of_first_row or
'template subject' in text_of_first_row
)
assert 'Delivered' in text_of_first_row
assert notification['to'] in content
assert notification['status'] in content
assert notification['template']['name'] in content
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page_title in page.h1.text.strip()
path_to_json = page.find("div", {'data-key': 'notifications'})['data-resource']

View File

@@ -8,7 +8,6 @@ from bs4 import BeautifulSoup
from app.main.views.jobs import get_time_left, get_status_filters
from tests import notification_json
from tests.app.test_utils import normalize_spaces
from tests.conftest import SERVICE_ONE_ID
from freezegun import freeze_time
@@ -81,7 +80,6 @@ def test_should_show_page_for_one_job(
status_argument,
expected_api_call,
):
response = logged_in_client.get(url_for(
'main.view_job',
service_id=service_one['id'],
@@ -92,8 +90,11 @@ def test_should_show_page_for_one_job(
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.text.strip() == 'thisisatest.csv'
assert page.find('div', {'class': 'sms-message-wrapper'}).text.strip() == (
'{}: Template <em>content</em> with & entity'.format(service_one['name'])
)
assert ' '.join(page.find('tbody').find('tr').text.split()) == (
'07123456789 template content Delivered 1 January at 11:10am'
'07123456789 Delivered 1 January at 11:10am'
)
assert page.find('div', {'data-key': 'notifications'})['data-resource'] == url_for(
'main.view_job_updates',
@@ -162,6 +163,7 @@ def test_should_show_job_in_progress(
@freeze_time("2016-01-01T00:00:00.061258")
def test_should_show_scheduled_job(
logged_in_client,
service_one,
active_user_with_permissions,
mock_get_service_template,
mock_get_scheduled_job,
@@ -171,21 +173,13 @@ def test_should_show_scheduled_job(
):
response = logged_in_client.get(url_for(
'main.view_job',
service_id=SERVICE_ONE_ID,
service_id=service_one['id'],
job_id=fake_uuid
))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert normalize_spaces(page.select('main p')[1].text) == (
'Sending Two week reminder today at midnight'
)
assert page.select('main p a')[0]['href'] == url_for(
'main.view_template_version',
service_id=SERVICE_ONE_ID,
template_id='5d729fbd-239c-44ab-b498-75a985f3198f',
version=1,
)
assert page.find('main').find_all('p')[1].text.strip() == 'Sending will start today at midnight'
assert page.find('input', {'type': 'submit', 'value': 'Cancel sending'})
@@ -262,7 +256,6 @@ def test_should_show_updates_for_one_job_as_json(
service_one,
active_user_with_permissions,
mock_get_notifications,
mock_get_service_template,
mock_get_job,
mocker,
fake_uuid,

View File

@@ -1,6 +1,8 @@
from freezegun import freeze_time
import pytest
from werkzeug.datastructures import MultiDict
from app.main.views.notifications import get_status_arg
from app.utils import (
REQUESTED_STATUSES,
FAILURE_STATUSES,
@@ -8,34 +10,63 @@ from app.utils import (
DELIVERED_STATUSES,
)
from tests.app.test_utils import normalize_spaces
from tests.conftest import mock_get_notification
@pytest.mark.parametrize('notification_status, expected_status', [
('created', 'Sending'),
('sending', 'Sending'),
('delivered', 'Delivered'),
('failed', 'Failed'),
('temporary-failure', 'Phone not accepting messages right now'),
('permanent-failure', 'Phone number doesnt exist'),
('technical-failure', 'Technical failure'),
@pytest.mark.parametrize('multidict_args, expected_statuses', [
([], REQUESTED_STATUSES),
([('status', '')], REQUESTED_STATUSES),
([('status', 'garbage')], REQUESTED_STATUSES),
([('status', 'sending')], SENDING_STATUSES),
([('status', 'delivered')], DELIVERED_STATUSES),
([('status', 'failed')], FAILURE_STATUSES),
])
def test_status_filters(mocker, multidict_args, expected_statuses):
mocker.patch('app.main.views.notifications.current_app')
args = MultiDict(multidict_args)
args['status'] = get_status_arg(args)
assert sorted(args['status']) == sorted(expected_statuses)
@freeze_time("2016-01-01 11:09:00.061258")
def test_notification_status_page_shows_details(
client_request,
mock_get_notification,
service_one,
fake_uuid,
):
page = client_request.get(
'main.view_notification',
service_id=service_one['id'],
notification_id=fake_uuid
)
assert page.find('div', {'class': 'sms-message-wrapper'}).text.strip() == 'service one: template content'
assert ' '.join(page.find('tbody').find('tr').text.split()) == '07123456789 Delivered 1 January at 11:10am'
mock_get_notification.assert_called_with(
service_one['id'],
fake_uuid
)
@pytest.mark.parametrize('notification_status, expected_big_number_vals', [
('created', [1, 1, 0, 0]),
('sending', [1, 1, 0, 0]),
('delivered', [1, 0, 1, 0]),
('temporary-failure', [1, 0, 0, 1]),
])
def test_notification_status_page_shows_correct_numbers(
client_request,
mocker,
service_one,
fake_uuid,
notification_status,
expected_status,
expected_big_number_vals
):
_mock_get_notification = mock_get_notification(
mocker,
fake_uuid,
notification_status=notification_status
)
mock_get_notification(mocker, fake_uuid, notification_status=notification_status)
page = client_request.get(
'main.view_notification',
@@ -43,14 +74,5 @@ def test_notification_status_page_shows_details(
notification_id=fake_uuid
)
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
'service one: hello Jo'
)
assert normalize_spaces(page.select('.ajax-block-container p')[0].text) == (
expected_status
)
_mock_get_notification.assert_called_with(
service_one['id'],
fake_uuid
)
big_numbers = page.find_all('div', {'class': 'big-number-number'})
assert expected_big_number_vals == [int(num.text.strip()) for num in big_numbers]

View File

@@ -1650,8 +1650,7 @@ def mock_get_notification(mocker, fake_uuid, notification_status='delivered'):
'name': 'Test User',
'email_address': 'test@user.gov.uk'
}
noti['personalisation'] = {'name': 'Jo'}
noti['template'] = template_json(service_id, str(generate_uuid()), content='hello ((name))')
noti['template'] = template_json(service_id, str(generate_uuid()))
return noti
return mocker.patch(