Download csv for job added.

Removed check for notifications so download button is always there.
This commit is contained in:
Nicholas Staples
2016-05-23 12:14:12 +01:00
parent 76662e1c84
commit 935f355d5c
3 changed files with 37 additions and 0 deletions

View File

@@ -76,6 +76,13 @@ def view_job(service_id, job_id):
version=job['template_version'])['data']
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
finished = job['status'] == 'finished'
if 'download' in request.args and request.args['download'] == 'csv':
csv_content = generate_notifications_csv(
notification_api_client.get_notifications_for_service(service_id, job_id)['notifications'])
return csv_content, 200, {
'Content-Type': 'text/csv; charset=utf-8',
'Content-Disposition': 'inline; filename="job_notifications.csv"'
}
return render_template(
'views/jobs/job.html',
notifications=notifications['notifications'],

View File

@@ -30,6 +30,12 @@
)}}
{% endif %}
<p class="bottom-gutter">
<a href="{{ request.url }}?&amp;download=csv" download class="heading-small">Download as a CSV file</a>
&emsp;
Delivery information is available for 7 days
</p>
{% include 'partials/jobs/status.html' %}
{% include 'partials/jobs/count.html' %}

View File

@@ -262,3 +262,27 @@ def test_should_download_notifications_for_a_service(app_,
assert response.status_code == 200
assert response.get_data(as_text=True) == csv_content
assert 'text/csv' in response.headers['Content-Type']
def test_should_download_notifications_for_a_job(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_job',
service_id=fake_uuid,
job_id=fake_uuid,
download='csv'))
csv_content = generate_notifications_csv(
mock_get_notifications(fake_uuid, job_id=fake_uuid)['notifications'])
assert response.status_code == 200
assert response.get_data(as_text=True) == csv_content
assert 'text/csv' in response.headers['Content-Type']