Revert "Merge pull request #1336 from alphagov/revert-show-notifications"

This reverts commit 7e354ff341, reversing
changes made to 6f3bcff32f.
This commit is contained in:
Chris Hill-Scott
2017-06-24 17:12:45 +01:00
parent 8115dab8e4
commit 9f20ea4b7e
21 changed files with 223 additions and 196 deletions

View File

@@ -9,6 +9,7 @@ from bs4 import BeautifulSoup
from app.main.views.jobs import get_time_left, get_status_filters
from tests import notification_json
from tests.conftest import SERVICE_ONE_ID
from tests.app.test_utils import normalize_spaces
from freezegun import freeze_time
@@ -92,13 +93,17 @@ 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]
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')
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 page_title in page.h1.text.strip()
path_to_json = page.find("div", {'data-key': 'notifications'})['data-resource']
@@ -131,6 +136,23 @@ def test_can_show_notifications(
assert json_content.keys() == {'counts', 'notifications'}
def test_shows_message_when_no_notifications(
client_request,
mock_get_detailed_service,
mock_get_notifications_with_no_notifications,
):
page = client_request.get(
'main.view_notifications',
service_id=SERVICE_ONE_ID,
message_type='sms',
)
assert normalize_spaces(page.select('tbody tr')[0].text) == (
'No messages found'
)
@pytest.mark.parametrize((
'initial_query_arguments,'
'form_post_data,'

View File

@@ -8,6 +8,7 @@ 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
@@ -80,6 +81,7 @@ 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'],
@@ -90,11 +92,8 @@ 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 Delivered 1 January at 11:10am'
'07123456789 template content Delivered 1 January at 11:10am'
)
assert page.find('div', {'data-key': 'notifications'})['data-resource'] == url_for(
'main.view_job_updates',
@@ -163,7 +162,6 @@ 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,
@@ -173,13 +171,21 @@ 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 page.find('main').find_all('p')[1].text.strip() == 'Sending will start today at midnight'
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('input', {'type': 'submit', 'value': 'Cancel sending'})
@@ -256,6 +262,7 @@ 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,8 +1,6 @@
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,
@@ -10,63 +8,34 @@ from app.utils import (
DELIVERED_STATUSES,
)
from tests.app.test_utils import normalize_spaces
from tests.conftest import mock_get_notification
@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),
@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'),
])
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_big_number_vals
expected_status,
):
mock_get_notification(mocker, fake_uuid, notification_status=notification_status)
_mock_get_notification = mock_get_notification(
mocker,
fake_uuid,
notification_status=notification_status
)
page = client_request.get(
'main.view_notification',
@@ -74,5 +43,17 @@ def test_notification_status_page_shows_correct_numbers(
notification_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]
assert normalize_spaces(page.select('.sms-message-recipient')[0].text) == (
'To: 07123456789'
)
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
)