mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Change activity to view to request 7 days data.
Cleaned up filters a bit so that if you want both templates email and sms is passed. Added mock assertion to test.
This commit is contained in:
@@ -2,6 +2,7 @@ from flask import url_for
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
from app.utils import generate_notifications_csv
|
||||
from tests import notification_json
|
||||
|
||||
|
||||
def test_should_return_list_of_all_jobs(app_,
|
||||
@@ -70,7 +71,6 @@ def test_should_show_updates_for_one_job_as_json(
|
||||
):
|
||||
service_id = job_data['service']
|
||||
job_id = job_data['id']
|
||||
file_name = job_data['original_file_name']
|
||||
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
@@ -101,13 +101,15 @@ def test_should_show_notifications_for_a_service(app_,
|
||||
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'])
|
||||
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
|
||||
|
||||
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email', 'sms']) # noqa
|
||||
|
||||
|
||||
def test_can_view_only_sms_notifications_for_a_service(app_,
|
||||
service_one,
|
||||
@@ -124,16 +126,49 @@ def test_can_view_only_sms_notifications_for_a_service(app_,
|
||||
response = client.get(url_for(
|
||||
'main.view_notifications',
|
||||
service_id=service_one['id'],
|
||||
type='sms'))
|
||||
template_type=['sms']))
|
||||
assert response.status_code == 200
|
||||
content = response.get_data(as_text=True)
|
||||
notifications = mock_get_notifications(service_one['id'])
|
||||
|
||||
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
|
||||
|
||||
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'],
|
||||
status=['delivered', 'failed'],
|
||||
template_type=['email']))
|
||||
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
|
||||
|
||||
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['delivered', 'failed'], template_type=['email']) # noqa
|
||||
|
||||
|
||||
def test_can_view_successful_notifications_for_a_service(app_,
|
||||
service_one,
|
||||
@@ -150,16 +185,46 @@ def test_can_view_successful_notifications_for_a_service(app_,
|
||||
response = client.get(url_for(
|
||||
'main.view_notifications',
|
||||
service_id=service_one['id'],
|
||||
status=['sent', 'delivered']))
|
||||
status=['delivered']))
|
||||
assert response.status_code == 200
|
||||
content = response.get_data(as_text=True)
|
||||
notifications = mock_get_notifications(service_one['id'])
|
||||
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
|
||||
|
||||
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'],
|
||||
status=['failed']))
|
||||
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
|
||||
|
||||
mock_get_notifications.assert_called_with(limit_days=7, page=1, service_id=service_one['id'], status=['failed'], template_type=['email', 'sms']) # noqa
|
||||
|
||||
|
||||
def test_should_show_notifications_for_a_service_with_next_previous(app_,
|
||||
service_one,
|
||||
|
||||
@@ -691,7 +691,8 @@ def mock_get_notifications(mocker):
|
||||
page=1,
|
||||
page_size=50,
|
||||
template_type=None,
|
||||
status=None):
|
||||
status=None,
|
||||
limit_days=None):
|
||||
return notification_json(service_id)
|
||||
return mocker.patch(
|
||||
'app.notification_api_client.get_notifications_for_service',
|
||||
@@ -705,7 +706,8 @@ def mock_get_notifications_with_previous_next(mocker):
|
||||
job_id=None,
|
||||
page=1,
|
||||
template_type=None,
|
||||
status=None):
|
||||
status=None,
|
||||
limit_days=None):
|
||||
return notification_json(service_id, with_links=True)
|
||||
return mocker.patch(
|
||||
'app.notification_api_client.get_notifications_for_service',
|
||||
|
||||
Reference in New Issue
Block a user