diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 19e305ef6..90f7623c7 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -18,7 +18,8 @@ from app import ( job_api_client, notification_api_client, service_api_client, - current_service) + current_service, + format_datetime_short) from app.main import main from app.utils import ( get_page_from_request, @@ -81,7 +82,10 @@ def view_job(service_id, job_id): 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"' + 'Content-Disposition': 'inline; filename="{} - {}.csv"'.format( + template['name'], + format_datetime_short(job['created_at']) + ) } return render_template( 'views/jobs/job.html', diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 145d6d7c4..46b5f50e9 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -248,6 +248,7 @@ def test_should_show_notifications_for_a_service_with_next_previous(app_, def test_should_download_notifications_for_a_service(app_, service_one, active_user_with_permissions, + mock_get_service_template, mock_get_notifications, mocker): with app_.test_request_context(): @@ -264,6 +265,7 @@ def test_should_download_notifications_for_a_service(app_, 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, mock_login, @@ -286,3 +288,4 @@ def test_should_download_notifications_for_a_job(app_, assert response.status_code == 200 assert response.get_data(as_text=True) == csv_content assert 'text/csv' in response.headers['Content-Type'] + assert 'sample template - 01 January at 11:09.csv"' in response.headers['Content-Disposition'] diff --git a/tests/conftest.py b/tests/conftest.py index 2ad9c78b6..cdad48284 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -793,6 +793,7 @@ def mock_get_job(mocker, job_data): def _get_job(service_id, job_id): job_data['id'] = job_id job_data['service'] = service_id + job_data['created_at'] = str(datetime.utcnow()) return {"data": job_data} return mocker.patch('app.job_api_client.get_job', side_effect=_get_job)