mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Fixed download bug for services with api notifications. Re-organised the mock job and job_json methods.
This commit is contained in:
@@ -2,7 +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, job_json_with_created_by
|
||||
from tests import (notification_json, job_json)
|
||||
from tests.conftest import fake_uuid
|
||||
from tests.conftest import mock_get_job as mock_get_job1
|
||||
from freezegun import freeze_time
|
||||
@@ -31,17 +31,16 @@ def test_should_show_page_for_one_job(
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_template,
|
||||
mock_get_job,
|
||||
mocker,
|
||||
mock_get_notifications
|
||||
mock_get_notifications,
|
||||
fake_uuid
|
||||
):
|
||||
data = job_json_with_created_by(service_id=service_one['id'])
|
||||
job_id = data['id']
|
||||
file_name = data['original_file_name']
|
||||
file_name = mock_get_job(service_one['id'], fake_uuid)['data']['original_file_name']
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user_with_permissions, mocker, service_one)
|
||||
mock_get_job1(mocker=mocker, job_data=data)
|
||||
response = client.get(url_for('main.view_job', service_id=service_one['id'], job_id=job_id))
|
||||
response = client.get(url_for('main.view_job', service_id=service_one['id'], job_id=fake_uuid))
|
||||
|
||||
assert response.status_code == 200
|
||||
content = response.get_data(as_text=True)
|
||||
@@ -55,15 +54,15 @@ def test_should_show_updates_for_one_job_as_json(
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
mock_get_notifications,
|
||||
mocker
|
||||
mock_get_job,
|
||||
mocker,
|
||||
fake_uuid
|
||||
):
|
||||
job_id = fake_uuid()
|
||||
data = job_json_with_created_by(job_id, service_one['id'])
|
||||
job_json = mock_get_job(service_one['id'], fake_uuid)['data']
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user_with_permissions, mocker, service_one)
|
||||
mock_get_job1(mocker=mocker, job_data=data)
|
||||
response = client.get(url_for('main.view_job_updates', service_id=service_one['id'], job_id=job_id))
|
||||
response = client.get(url_for('main.view_job_updates', service_id=service_one['id'], job_id=fake_uuid))
|
||||
|
||||
assert response.status_code == 200
|
||||
content = json.loads(response.get_data(as_text=True))
|
||||
@@ -72,7 +71,7 @@ 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']
|
||||
assert 'Uploaded by Test User' in content['status']
|
||||
assert job_json['status'] in content['status']
|
||||
|
||||
|
||||
def test_should_show_notifications_for_a_service(app_,
|
||||
@@ -91,7 +90,7 @@ def test_should_show_notifications_for_a_service(app_,
|
||||
assert notification['to'] in content
|
||||
assert notification['status'] in content
|
||||
assert notification['template']['name'] in content
|
||||
assert '.csv' in content
|
||||
assert 'Download as a CSV file' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Activity'
|
||||
|
||||
@@ -119,7 +118,7 @@ def test_can_view_only_sms_notifications_for_a_service(app_,
|
||||
assert notification['to'] in content
|
||||
assert notification['status'] in content
|
||||
assert notification['template']['name'] in content
|
||||
assert '.csv' in content
|
||||
assert 'Download as a CSV file' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Text messages'
|
||||
|
||||
@@ -147,7 +146,7 @@ def test_can_view_only_email_notifications_for_a_service(app_,
|
||||
assert notification['to'] in content
|
||||
assert notification['status'] in content
|
||||
assert notification['template']['name'] in content
|
||||
assert '.csv' in content
|
||||
assert 'Download as a CSV file' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Emails'
|
||||
|
||||
@@ -173,7 +172,7 @@ def test_can_view_successful_notifications_for_a_service(app_,
|
||||
assert notification['to'] in content
|
||||
assert notification['status'] in content
|
||||
assert notification['template']['name'] in content
|
||||
assert '.csv' in content
|
||||
assert 'Download as a CSV file' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Successful emails and text messages'
|
||||
|
||||
@@ -199,7 +198,7 @@ def test_can_view_failed_notifications_for_a_service(app_,
|
||||
assert notification['to'] in content
|
||||
assert notification['status'] in content
|
||||
assert notification['template']['name'] in content
|
||||
assert '.csv' in content
|
||||
assert 'Download as a CSV file' in content
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Failed emails and text messages'
|
||||
|
||||
@@ -265,6 +264,30 @@ def test_should_download_notifications_for_a_service(app_,
|
||||
assert 'text/csv' in response.headers['Content-Type']
|
||||
|
||||
|
||||
def test_should_download_api_notifications_for_a_service(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_job,
|
||||
mock_get_notifications,
|
||||
mock_get_template_version,
|
||||
mock_has_permissions,
|
||||
fake_uuid):
|
||||
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=fake_uuid,
|
||||
download='csv'))
|
||||
notifications = mock_get_notifications(fake_uuid)['notifications']
|
||||
assert all([x['job'] is None for x in notifications])
|
||||
csv_content = generate_notifications_csv(notifications)
|
||||
assert response.status_code == 200
|
||||
assert response.get_data(as_text=True) == csv_content
|
||||
assert 'text/csv' in response.headers['Content-Type']
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_should_download_notifications_for_a_job(app_,
|
||||
api_user_active,
|
||||
|
||||
@@ -7,7 +7,7 @@ from glob import glob
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from unittest.mock import ANY
|
||||
from tests import validate_route_permission, job_json_with_created_by
|
||||
from tests import (validate_route_permission, job_json)
|
||||
|
||||
template_types = ['email', 'sms']
|
||||
|
||||
@@ -321,20 +321,19 @@ def test_create_job_should_call_api(
|
||||
app_,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
job_data,
|
||||
mock_create_job,
|
||||
mock_get_job,
|
||||
mock_get_notifications,
|
||||
mock_get_service_template,
|
||||
mocker
|
||||
mocker,
|
||||
fake_uuid
|
||||
):
|
||||
service_id = service_one['id']
|
||||
job_id = job_data['id']
|
||||
original_file_name = job_data['original_file_name']
|
||||
template_id = job_data['template']
|
||||
notification_count = job_data['notification_count']
|
||||
|
||||
from tests.conftest import mock_get_job as mock_get_job1
|
||||
data = mock_get_job(service_one['id'], fake_uuid)['data']
|
||||
job_id = data['id']
|
||||
original_file_name = data['original_file_name']
|
||||
template_id = data['template']
|
||||
notification_count = data['notification_count']
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user_with_permissions, mocker, service_one)
|
||||
@@ -344,9 +343,7 @@ def test_create_job_should_call_api(
|
||||
'notification_count': notification_count,
|
||||
'valid': True}
|
||||
url = url_for('main.start_job', service_id=service_one['id'], upload_id=job_id)
|
||||
data = job_json_with_created_by(service_id=service_one['id'], job_id=job_data['id'])
|
||||
mock_get_job1(mocker=mocker, job_data=data)
|
||||
response = client.post(url, data=job_data, follow_redirects=True)
|
||||
response = client.post(url, data={}, follow_redirects=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert original_file_name in response.get_data(as_text=True)
|
||||
@@ -357,14 +354,15 @@ def test_check_messages_should_revalidate_file_when_uploading_file(
|
||||
app_,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
job_data,
|
||||
mock_create_job,
|
||||
mock_get_job,
|
||||
mock_get_service_template_with_placeholders,
|
||||
mock_s3_upload,
|
||||
mocker,
|
||||
mock_has_permissions,
|
||||
mock_get_service_statistics,
|
||||
mock_get_users_by_service
|
||||
mock_get_users_by_service,
|
||||
fake_uuid
|
||||
):
|
||||
|
||||
service_id = service_one['id']
|
||||
@@ -377,16 +375,17 @@ def test_check_messages_should_revalidate_file_when_uploading_file(
|
||||
+447700900986,,,,
|
||||
"""
|
||||
)
|
||||
data = mock_get_job(service_one['id'], fake_uuid)['data']
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(active_user_with_permissions, mocker, service_one)
|
||||
with client.session_transaction() as session:
|
||||
session['upload_data'] = {'original_file_name': 'invalid.csv',
|
||||
'template_id': job_data['template'],
|
||||
'notification_count': job_data['notification_count'],
|
||||
'template_id': data['template'],
|
||||
'notification_count': data['notification_count'],
|
||||
'valid': True}
|
||||
response = client.post(
|
||||
url_for('main.start_job', service_id=service_id, upload_id=job_data['id']),
|
||||
url_for('main.start_job', service_id=service_id, upload_id=data['id']),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
|
||||
content_type='multipart/form-data',
|
||||
follow_redirects=True
|
||||
|
||||
Reference in New Issue
Block a user