mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 18:37:33 -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,
|
||||
|
||||
Reference in New Issue
Block a user