2016-01-15 17:46:09 +00:00
|
|
|
from flask import url_for
|
2016-01-29 15:35:35 +00:00
|
|
|
from bs4 import BeautifulSoup
|
2016-03-02 17:36:20 +00:00
|
|
|
import json
|
2016-04-12 14:19:51 +01:00
|
|
|
from app.utils import generate_notifications_csv
|
2016-04-28 15:50:05 +01:00
|
|
|
from tests import notification_json
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
|
|
|
|
2016-01-27 12:22:32 +00:00
|
|
|
def test_should_return_list_of_all_jobs(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
2016-01-27 16:30:33 +00:00
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
2016-01-29 15:35:35 +00:00
|
|
|
mock_login,
|
2016-04-04 16:53:52 +01:00
|
|
|
mock_get_service,
|
2016-03-23 12:15:57 +00:00
|
|
|
mock_get_jobs,
|
|
|
|
|
mock_has_permissions):
|
2016-01-15 15:15:35 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-01-15 17:46:09 +00:00
|
|
|
response = client.get(url_for('main.view_jobs', service_id=101))
|
2015-12-17 16:21:34 +00:00
|
|
|
|
2016-01-11 16:03:41 +00:00
|
|
|
assert response.status_code == 200
|
2016-01-29 15:35:35 +00:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string == 'Notifications activity'
|
|
|
|
|
jobs = page.tbody.find_all('tr')
|
|
|
|
|
assert len(jobs) == 5
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
|
|
|
|
2016-03-02 17:36:20 +00:00
|
|
|
def test_should_show_page_for_one_job(
|
|
|
|
|
app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
job_data,
|
|
|
|
|
mock_get_job,
|
2016-03-23 12:15:57 +00:00
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions
|
2016-03-02 17:36:20 +00:00
|
|
|
):
|
2016-01-29 15:35:35 +00:00
|
|
|
service_id = job_data['service']
|
|
|
|
|
job_id = job_data['id']
|
|
|
|
|
file_name = job_data['original_file_name']
|
2016-01-11 16:03:41 +00:00
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
client.login(api_user_active)
|
2016-01-29 15:35:35 +00:00
|
|
|
response = client.get(url_for('main.view_job', service_id=service_id, job_id=job_id))
|
2016-01-11 16:03:41 +00:00
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2016-03-02 13:17:24 +00:00
|
|
|
content = response.get_data(as_text=True)
|
|
|
|
|
assert "Test Service: Your vehicle tax is about to expire" in content
|
|
|
|
|
assert file_name in content
|
2016-03-02 17:36:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_updates_for_one_job_as_json(
|
|
|
|
|
app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
job_data,
|
|
|
|
|
mock_get_job,
|
2016-03-23 12:15:57 +00:00
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions
|
2016-03-02 17:36:20 +00:00
|
|
|
):
|
|
|
|
|
service_id = job_data['service']
|
|
|
|
|
job_id = job_data['id']
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for('main.view_job_updates', service_id=service_id, job_id=job_id))
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
content = json.loads(response.get_data(as_text=True))
|
2016-03-21 13:07:12 +00:00
|
|
|
assert 'processed' in content['counts']
|
2016-03-02 17:36:20 +00:00
|
|
|
assert 'queued' in content['counts']
|
|
|
|
|
assert 'Recipient' in content['notifications']
|
|
|
|
|
assert 'Status' in content['notifications']
|
|
|
|
|
assert 'Started' in content['status']
|
2016-03-16 16:57:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_show_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
2016-03-23 12:15:57 +00:00
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
2016-03-16 16:57:10 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for('main.view_notifications', service_id=service_one['id']))
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
content = response.get_data(as_text=True)
|
2016-04-28 15:50:05 +01:00
|
|
|
notifications = notification_json(service_one['id'])
|
2016-03-16 16:57:10 +00:00
|
|
|
notification = notifications['notifications'][0]
|
|
|
|
|
assert notification['to'] in content
|
|
|
|
|
assert notification['status'] in content
|
|
|
|
|
assert notification['template']['name'] in content
|
|
|
|
|
assert '.csv' in content
|
2016-04-29 15:24:48 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Activity'
|
2016-03-16 16:57:10 +00:00
|
|
|
|
2016-04-28 15:50:05 +01:00
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email', 'sms']) # noqa
|
|
|
|
|
|
2016-03-16 16:57:10 +00:00
|
|
|
|
2016-04-04 16:34:06 +01:00
|
|
|
def test_can_view_only_sms_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
2016-04-29 15:24:48 +01:00
|
|
|
template_type='sms',
|
|
|
|
|
status='delivered,failed'))
|
2016-04-28 15:50:05 +01:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
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
|
|
|
|
|
assert '.csv' in content
|
2016-04-29 15:24:48 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Text messages'
|
2016-04-28 15:50:05 +01:00
|
|
|
|
|
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['sms']) # noqa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_view_only_email_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
2016-04-29 15:24:48 +01:00
|
|
|
status='delivered,failed',
|
|
|
|
|
template_type='email'))
|
2016-04-04 16:34:06 +01:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
content = response.get_data(as_text=True)
|
2016-04-28 15:50:05 +01:00
|
|
|
|
|
|
|
|
notifications = notification_json(service_one['id'])
|
2016-04-04 16:34:06 +01:00
|
|
|
notification = notifications['notifications'][0]
|
|
|
|
|
assert notification['to'] in content
|
|
|
|
|
assert notification['status'] in content
|
|
|
|
|
assert notification['template']['name'] in content
|
|
|
|
|
assert '.csv' in content
|
2016-04-29 15:24:48 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Emails'
|
2016-04-04 16:34:06 +01:00
|
|
|
|
2016-04-28 15:50:05 +01:00
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email']) # noqa
|
|
|
|
|
|
2016-04-04 16:34:06 +01:00
|
|
|
|
|
|
|
|
def test_can_view_successful_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
2016-04-29 15:24:48 +01:00
|
|
|
status='delivered'))
|
2016-04-04 16:34:06 +01:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
content = response.get_data(as_text=True)
|
2016-04-28 15:50:05 +01:00
|
|
|
notifications = notification_json(service_one['id'])
|
2016-04-04 16:34:06 +01:00
|
|
|
notification = notifications['notifications'][0]
|
|
|
|
|
assert notification['to'] in content
|
|
|
|
|
assert notification['status'] in content
|
|
|
|
|
assert notification['template']['name'] in content
|
|
|
|
|
assert '.csv' in content
|
2016-04-29 15:24:48 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Successful emails and text messages'
|
2016-04-04 16:34:06 +01:00
|
|
|
|
2016-04-28 15:50:05 +01:00
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered'], template_type=['email', 'sms']) # noqa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_view_failed_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
2016-04-29 15:24:48 +01:00
|
|
|
status='failed'))
|
2016-04-28 15:50:05 +01:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
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
|
|
|
|
|
assert '.csv' in content
|
2016-04-29 15:24:48 +01:00
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Failed emails and text messages'
|
2016-04-28 15:50:05 +01:00
|
|
|
|
|
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed'], template_type=['email', 'sms']) # noqa
|
|
|
|
|
|
2016-04-04 16:34:06 +01:00
|
|
|
|
2016-04-29 15:24:48 +01:00
|
|
|
def test_can_view_failed_combination_of_notification_type_and_status(
|
|
|
|
|
app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions
|
|
|
|
|
):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
status='failed',
|
|
|
|
|
template_type='sms'))
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
assert page.h1.string.strip() == 'Failed text messages'
|
|
|
|
|
|
|
|
|
|
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed'], template_type=['sms']) # noqa
|
|
|
|
|
|
|
|
|
|
|
2016-03-16 16:57:10 +00:00
|
|
|
def test_should_show_notifications_for_a_service_with_next_previous(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
2016-03-23 12:15:57 +00:00
|
|
|
mock_get_notifications_with_previous_next,
|
|
|
|
|
mock_has_permissions):
|
2016-03-16 16:57:10 +00:00
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for('main.view_notifications', service_id=service_one['id'], page=2))
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
content = response.get_data(as_text=True)
|
|
|
|
|
assert url_for('main.view_notifications', service_id=service_one['id'], page=3) in content
|
|
|
|
|
assert url_for('main.view_notifications', service_id=service_one['id'], page=1) in content
|
|
|
|
|
assert 'Previous page' in content
|
|
|
|
|
assert 'Next page' in content
|
2016-04-12 14:19:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_download_notifications_for_a_service(app_,
|
|
|
|
|
service_one,
|
|
|
|
|
api_user_active,
|
|
|
|
|
mock_login,
|
|
|
|
|
mock_get_user,
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
mock_get_service,
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
mock_has_permissions):
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
'main.view_notifications',
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
download='csv'))
|
|
|
|
|
csv_content = generate_notifications_csv(
|
|
|
|
|
mock_get_notifications(service_one['id'])['notifications'])
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response.get_data(as_text=True) == csv_content
|
|
|
|
|
assert 'text/csv' in response.headers['Content-Type']
|