Notification history page added and pagination, tests all working.

This commit is contained in:
Nicholas Staples
2016-03-16 16:57:10 +00:00
parent f41106f4db
commit b0ca855ba8
13 changed files with 351 additions and 24 deletions

View File

@@ -32,7 +32,7 @@ def service_json(id_, name, users, limit=1000, active=False, restricted=True):
}
def template_json(id_, name, type_, content, service_id):
def template_json(service_id, id_=1, name="sample template", type_="sms", content="template content"):
return {
'id': id_,
'name': name,
@@ -117,13 +117,40 @@ def job_json():
return data
def notification_json():
def notification_json(service_id,
job=None,
template=None,
to='07123456789',
status='sent',
sent_at=None,
created_at=None,
with_links=False):
import datetime
if job is None:
job = job_json()
if template is None:
template = template_json(service_id)
if sent_at is None:
sent_at = str(datetime.datetime.now().time())
if created_at is None:
created_at = str(datetime.datetime.now().time())
links = {}
if with_links:
links = {
'prev': '/service/{}/notifications'.format(service_id),
'next': '/service/{}/notifications'.format(service_id),
'last': '/service/{}/notifications'.format(service_id)
}
data = {
'notifications': [{
'sent_at': str(datetime.datetime.now().time())
'to': to,
'template': {'id': template['id'], 'name': template['name']},
'job': {'id': job['id'], 'file_name': job['file_name']},
'sent_at': sent_at,
'status': status,
'created_at': created_at
} for i in range(5)],
'links': {}
'links': links
}
return data

View File

@@ -80,3 +80,45 @@ def test_should_show_updates_for_one_job_as_json(
assert 'Recipient' in content['notifications']
assert 'Status' in content['notifications']
assert 'Started' in content['status']
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,
mock_get_notifications):
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)
notifications = mock_get_notifications(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
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,
mock_get_notifications_with_previous_next):
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

View File

@@ -158,7 +158,7 @@ def mock_delete_service(mocker, mock_get_service):
def mock_get_service_template(mocker):
def _create(service_id, template_id):
template = template_json(
template_id, "Two week reminder", "sms", "Your vehicle tax is about to expire", service_id)
service_id, template_id, "Two week reminder", "sms", "Your vehicle tax is about to expire")
return {'data': template}
return mocker.patch(
@@ -169,7 +169,7 @@ def mock_get_service_template(mocker):
def mock_get_service_email_template(mocker):
def _create(service_id, template_id):
template = template_json(
template_id, "Two week reminder", "email", "Your vehicle tax is about to expire", service_id)
service_id, template_id, "Two week reminder", "email", "Your vehicle tax is about to expire")
return {'data': template}
return mocker.patch(
@@ -180,7 +180,7 @@ def mock_get_service_email_template(mocker):
def mock_create_service_template(mocker):
def _create(name, type_, content, service):
template = template_json(
101, name, type_, content, service)
service, 101, name, type_, content)
return {'data': template}
return mocker.patch(
@@ -192,7 +192,7 @@ def mock_create_service_template(mocker):
def mock_update_service_template(mocker):
def _update(id_, name, type_, content, service):
template = template_json(
id_, name, type_, content, service)
service, id_, name, type_, content)
return {'data': template}
return mocker.patch(
@@ -205,17 +205,13 @@ def mock_get_service_templates(mocker):
def _create(service_id):
return {'data': [
template_json(
1, "sms_template_one", "sms", "sms template one content", service_id
),
service_id, 1, "sms_template_one", "sms", "sms template one content"),
template_json(
2, "sms_template_two", "sms", "sms template two content", service_id
),
service_id, 2, "sms_template_two", "sms", "sms template two content"),
template_json(
3, "email_template_one", "email", "email template one content", service_id
),
service_id, 3, "email_template_one", "email", "email template one content"),
template_json(
4, "email_template_two", "email", "email template two content", service_id
)
service_id, 4, "email_template_two", "email", "email template two content")
]}
return mocker.patch(
@@ -227,8 +223,7 @@ def mock_get_service_templates(mocker):
def mock_delete_service_template(mocker):
def _delete(service_id, template_id):
template = template_json(
template_id, "Template to delete",
"sms", "content to be deleted", service_id)
service_id, template_id, "Template to delete", "sms", "content to be deleted")
return {'data': template}
return mocker.patch(
@@ -580,8 +575,18 @@ def mock_get_jobs(mocker):
@pytest.fixture(scope='function')
def mock_get_notifications(mocker):
def _get_notifications(service_id, job_id):
return notification_json()
def _get_notifications(service_id, job_id=None, page=1):
return notification_json(service_id)
return mocker.patch(
'app.notification_api_client.get_notifications_for_service',
side_effect=_get_notifications
)
@pytest.fixture(scope='function')
def mock_get_notifications_with_previous_next(mocker):
def _get_notifications(service_id, job_id=None, page=1):
return notification_json(service_id, with_links=True)
return mocker.patch(
'app.notification_api_client.get_notifications_for_service',
side_effect=_get_notifications