mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 04:33:13 -04:00
Put uploaded files on the dashboard
This commit depends on and uses the data returned by: - [x] https://github.com/alphagov/notifications-api/pull/345 - [x] https://github.com/alphagov/notifications-api/pull/347 - [x] https://github.com/alphagov/notifications-admin/pull/612 It puts the last 5 jobs on the dashboard. This should be changed to all the jobs from the last 7 days when that parameter is available. It also: - links to the jobs page - makes the numbers on the jobs page consistent with the dashboard - makes the numbers on an individual job consistent with the appearance of the dashboard
This commit is contained in:
@@ -202,7 +202,7 @@ def format_datetime_normal(date):
|
|||||||
|
|
||||||
|
|
||||||
def format_datetime_short(date):
|
def format_datetime_short(date):
|
||||||
return gmt_timezones(date).strftime('%d %B at %H:%M')
|
return gmt_timezones(date).strftime('%d %B at %H:%M').lstrip('0')
|
||||||
|
|
||||||
|
|
||||||
def format_time(date):
|
def format_time(date):
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
.dashboard {
|
.dashboard {
|
||||||
table th {
|
|
||||||
font-size: 0;
|
table {
|
||||||
|
th {
|
||||||
|
@include core-16;
|
||||||
|
padding-top: 0;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
@include core-19;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,12 +25,9 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: right;
|
|
||||||
margin-bottom: $gutter-half;
|
margin-bottom: $gutter-half;
|
||||||
height: $gutter-half;
|
height: $gutter-half;
|
||||||
color: $govuk-blue;
|
color: $govuk-blue;
|
||||||
text-align: left;
|
|
||||||
color: $govuk-blue;
|
|
||||||
|
|
||||||
span {
|
span {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -47,3 +54,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.file-list {
|
||||||
|
|
||||||
|
&-filename {
|
||||||
|
@include bold-19;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-hint {
|
||||||
|
@include core-16;
|
||||||
|
display: block;
|
||||||
|
color: $secondary-text-colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from flask_login import login_required
|
|||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app import (
|
from app import (
|
||||||
|
job_api_client,
|
||||||
statistics_api_client,
|
statistics_api_client,
|
||||||
service_api_client,
|
service_api_client,
|
||||||
template_statistics_client
|
template_statistics_client
|
||||||
@@ -217,4 +218,5 @@ def get_dashboard_statistics_for_service(service_id):
|
|||||||
'sms_allowance_remaining': max(0, (sms_free_allowance - sms_sent)),
|
'sms_allowance_remaining': max(0, (sms_free_allowance - sms_sent)),
|
||||||
'sms_chargeable': max(0, sms_sent - sms_free_allowance),
|
'sms_chargeable': max(0, sms_sent - sms_free_allowance),
|
||||||
'sms_rate': sms_rate,
|
'sms_rate': sms_rate,
|
||||||
|
'jobs': job_api_client.get_job(service_id, limit_days=7)['data']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,12 +90,13 @@ def view_job(service_id, job_id):
|
|||||||
return render_template(
|
return render_template(
|
||||||
'views/jobs/job.html',
|
'views/jobs/job.html',
|
||||||
notifications=notifications['notifications'],
|
notifications=notifications['notifications'],
|
||||||
counts={
|
job=job,
|
||||||
'queued': 0 if finished else job['notification_count'],
|
|
||||||
'sent': job['notification_count'] if finished else 0
|
|
||||||
},
|
|
||||||
uploaded_at=job['created_at'],
|
uploaded_at=job['created_at'],
|
||||||
finished_at=job['updated_at'] if finished else None,
|
finished=job.get('notifications_sent', 0) and ((
|
||||||
|
job.get('notifications_sent', 0) -
|
||||||
|
job.get('notifications_delivered', 0) -
|
||||||
|
job.get('notifications_failed', 0)
|
||||||
|
) == 0),
|
||||||
uploaded_file_name=job['original_file_name'],
|
uploaded_file_name=job['original_file_name'],
|
||||||
first_email_template=[
|
first_email_template=[
|
||||||
template for template in service_api_client.get_service_templates(service_id)['data']
|
template for template in service_api_client.get_service_templates(service_id)['data']
|
||||||
@@ -104,9 +105,7 @@ def view_job(service_id, job_id):
|
|||||||
template=Template(
|
template=Template(
|
||||||
template,
|
template,
|
||||||
prefix=current_service['name']
|
prefix=current_service['name']
|
||||||
),
|
)
|
||||||
job_id=job_id,
|
|
||||||
created_by=job['created_by']['name']
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -116,24 +115,27 @@ def view_job(service_id, job_id):
|
|||||||
def view_job_updates(service_id, job_id):
|
def view_job_updates(service_id, job_id):
|
||||||
job = job_api_client.get_job(service_id, job_id)['data']
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
|
||||||
finished = job['status'] == 'finished'
|
finished = (
|
||||||
|
job.get('notifications_sent', 0) -
|
||||||
|
job.get('notifications_delivered', 0) -
|
||||||
|
job.get('notifications_failed', 0)
|
||||||
|
) == 0
|
||||||
return jsonify(**{
|
return jsonify(**{
|
||||||
'counts': render_template(
|
'counts': render_template(
|
||||||
'partials/jobs/count.html',
|
'partials/jobs/count.html',
|
||||||
counts={
|
job=job,
|
||||||
'queued': 0 if finished else job['notification_count'],
|
finished=finished
|
||||||
'sent': job['notification_count'] if finished else 0
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
'notifications': render_template(
|
'notifications': render_template(
|
||||||
'partials/jobs/notifications.html',
|
'partials/jobs/notifications.html',
|
||||||
notifications=notifications['notifications']
|
job=job,
|
||||||
|
notifications=notifications['notifications'],
|
||||||
|
finished=finished
|
||||||
),
|
),
|
||||||
'status': render_template(
|
'status': render_template(
|
||||||
'partials/jobs/status.html',
|
'partials/jobs/status.html',
|
||||||
uploaded_at=job['created_at'],
|
job=job,
|
||||||
finished_at=job['updated_at'] if finished else None,
|
finished=finished
|
||||||
created_by=job['created_by']['name']
|
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
{% if label_link %}
|
{% if label_link %}
|
||||||
<a class="big-number-label" href="{{ label_link }}">{{ label }}</a>
|
<a class="big-number-label" href="{{ label_link }}">{{ label }}</a>
|
||||||
<a class="big-number-overlay-link" href="{{ label_link }}" aria-hidden="true"></a>
|
<a class="big-number-overlay-link" href="{{ label_link }}" aria-hidden="true"></a>
|
||||||
{% else %}
|
{% elif label %}
|
||||||
<span class="big-number-label">{{ label }}</span>
|
<span class="big-number-label">{{ label }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{% from "components/big-number.html" import big_number %}
|
{% from "components/big-number.html" import big_number %}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
{% if not finished_at %}
|
{% if not finished %}
|
||||||
data-module="update-content"
|
data-module="update-content"
|
||||||
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
|
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
|
||||||
data-key="counts"
|
data-key="counts"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -12,12 +12,17 @@
|
|||||||
<ul class="grid-row job-totals">
|
<ul class="grid-row job-totals">
|
||||||
<li class="column-one-quarter">
|
<li class="column-one-quarter">
|
||||||
{{ big_number(
|
{{ big_number(
|
||||||
counts.queued, 'queued'
|
job.get('notifications_sent', 0) - job.get('notifications_delivered', 0) - job.get('notifications_failed', 0), 'sending'
|
||||||
)}}
|
)}}
|
||||||
</li>
|
</li>
|
||||||
<li class="column-one-quarter">
|
<li class="column-one-quarter">
|
||||||
{{ big_number(
|
{{ big_number(
|
||||||
counts.sent, 'processed'
|
job.get('notifications_delivered', 0), 'delivered'
|
||||||
|
)}}
|
||||||
|
</li>
|
||||||
|
<li class="column-one-quarter">
|
||||||
|
{{ big_number(
|
||||||
|
job.notifications_failed, 'failed'
|
||||||
)}}
|
)}}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
|
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
{% if not finished_at %}
|
{% if not finished %}
|
||||||
data-module="update-content"
|
data-module="update-content"
|
||||||
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
|
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
|
||||||
data-key="notifications"
|
data-key="notifications"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<div
|
<div
|
||||||
{% if not finished_at %}
|
{% if not finished %}
|
||||||
data-module="update-content"
|
data-module="update-content"
|
||||||
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job_id)}}"
|
data-resource="{{url_for(".view_job_updates", service_id=current_service.id, job_id=job.id)}}"
|
||||||
data-key="status"
|
data-key="status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>
|
>
|
||||||
<p class='heading-small'>
|
<p class='heading-small'>
|
||||||
Sent by {{ created_by }} on {{ uploaded_at|format_datetime_short }}
|
Uploaded by {{ job.created_by.name }} on {{ job.created_at|format_datetime_short }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
35
app/templates/views/dashboard/_jobs.html
Normal file
35
app/templates/views/dashboard/_jobs.html
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
|
||||||
|
{% from "components/big-number.html" import big_number %}
|
||||||
|
|
||||||
|
{% call(item, row_number) list_table(
|
||||||
|
jobs,
|
||||||
|
caption="Recent batch jobs",
|
||||||
|
caption_visible=False,
|
||||||
|
empty_message='You haven’t sent any batch messages yet',
|
||||||
|
field_headings=[
|
||||||
|
'File',
|
||||||
|
right_aligned_field_heading('Sending'),
|
||||||
|
right_aligned_field_heading('Delivered'),
|
||||||
|
right_aligned_field_heading('Failed')
|
||||||
|
],
|
||||||
|
field_headings_visible=True
|
||||||
|
) %}
|
||||||
|
{% call field() %}
|
||||||
|
<div class="file-list">
|
||||||
|
<a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||||
|
<span class="file-list-hint">Uploaded {{ item.created_at|format_datetime_short }}</span>
|
||||||
|
</div
|
||||||
|
{% endcall %}
|
||||||
|
{% call field(align='right') %}
|
||||||
|
{{ big_number(
|
||||||
|
item.get('notifications_sent', 0) - item.get('notifications_delivered', 0) - item.get('notifications_failed', 0),
|
||||||
|
smaller=True
|
||||||
|
) }}
|
||||||
|
{% endcall %}
|
||||||
|
{% call field(align='right') %}
|
||||||
|
{{ big_number(item.get('notifications_delivered', 0), smaller=True) }}
|
||||||
|
{% endcall %}
|
||||||
|
{% call field(align='right', status='error' if 0 else '') %}
|
||||||
|
{{ big_number(item.get('notifications_failed', 0), smaller=True) }}
|
||||||
|
{% endcall %}
|
||||||
|
{% endcall %}
|
||||||
@@ -8,9 +8,10 @@
|
|||||||
) %}
|
) %}
|
||||||
{% call field() %}
|
{% call field() %}
|
||||||
<a href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
<a href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||||
|
{{ item.created_at|format_datetime }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call field() %}
|
{% call field() %}
|
||||||
{{ item.created_at|format_datetime }}
|
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call field(align='right') %}
|
{% call field(align='right') %}
|
||||||
{{ item.notification_count }}
|
{{ item.notification_count }}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{% from "components/big-number.html" import big_number, big_number_with_status %}
|
{% from "components/big-number.html" import big_number, big_number_with_status %}
|
||||||
{% from "components/show-more.html" import show_more %}
|
{% from "components/show-more.html" import show_more %}
|
||||||
{% from "components/message-count-label.html" import message_count_label %}
|
{% from "components/message-count-label.html" import message_count_label %}
|
||||||
|
{% from "components/table.html" import list_table, field, right_aligned_field_heading, hidden_field_heading %}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
data-module="update-content"
|
data-module="update-content"
|
||||||
@@ -48,6 +49,14 @@
|
|||||||
) }}
|
) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if jobs %}
|
||||||
|
{% include 'views/dashboard/_jobs.html' %}
|
||||||
|
{{ show_more(
|
||||||
|
url_for('.view_jobs', service_id=current_service.id),
|
||||||
|
'See all uploaded files'
|
||||||
|
) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if current_user.has_permissions(['manage_settings'], admin_override=True) %}
|
{% if current_user.has_permissions(['manage_settings'], admin_override=True) %}
|
||||||
<h2 class='heading-medium'>This year</h2>
|
<h2 class='heading-medium'>This year</h2>
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,12 @@
|
|||||||
{% extends "withnav_template.html" %}
|
{% extends "withnav_template.html" %}
|
||||||
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
|
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
Notifications activity – GOV.UK Notify
|
Notifications activity – GOV.UK Notify
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block maincolumn_content %}
|
{% block maincolumn_content %}
|
||||||
|
<h1 class="heading-large">Uploaded files</h1>
|
||||||
<h1 class="heading-large">Notifications activity</h1>
|
<div class="dashboard">
|
||||||
<p>
|
{% include 'views/dashboard/_jobs.html' %}
|
||||||
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, page=1) }}">All messages</a>
|
</div>
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, type="sms", page=1) }}">Text messages</a> 
|
|
||||||
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, type="email", page=1) }}">Email messages</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, status=['sent', 'delivered'], page=1) }}">Successful messages</a> 
|
|
||||||
<a href="{{ url_for(".view_notifications", service_id=current_service.id, job_id=job_id, status=['failed', 'complaint', 'bounce'], page=1) }}">Failed messages</a>
|
|
||||||
</p>
|
|
||||||
{% call(item, row_number) list_table(
|
|
||||||
jobs,
|
|
||||||
caption="Recent activity",
|
|
||||||
caption_visible=False,
|
|
||||||
empty_message='You haven’t sent any notifications yet',
|
|
||||||
field_headings=['Job', 'Time', 'Uploaded by', right_aligned_field_heading('Status')]
|
|
||||||
) %}
|
|
||||||
{% call field() %}
|
|
||||||
<a href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
|
|
||||||
{% endcall %}
|
|
||||||
{% call field() %}
|
|
||||||
{{ item.created_at | format_datetime}}
|
|
||||||
{% endcall %}
|
|
||||||
{% call field() %}
|
|
||||||
{{ item.created_by.name }}
|
|
||||||
{% endcall %}
|
|
||||||
{% call field(align='right') %}
|
|
||||||
{{ item.status }}
|
|
||||||
{% endcall %}
|
|
||||||
{% endcall %}
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def test_should_return_list_of_all_jobs(app_,
|
|||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string == 'Notifications activity'
|
assert page.h1.string == 'Uploaded files'
|
||||||
jobs = page.tbody.find_all('tr')
|
jobs = page.tbody.find_all('tr')
|
||||||
assert len(jobs) == 5
|
assert len(jobs) == 5
|
||||||
|
|
||||||
@@ -49,6 +49,7 @@ def test_should_show_page_for_one_job(
|
|||||||
assert "Delivered at 11:10" in content
|
assert "Delivered at 11:10" in content
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
def test_should_show_updates_for_one_job_as_json(
|
def test_should_show_updates_for_one_job_as_json(
|
||||||
app_,
|
app_,
|
||||||
service_one,
|
service_one,
|
||||||
@@ -66,12 +67,15 @@ def test_should_show_updates_for_one_job_as_json(
|
|||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
content = json.loads(response.get_data(as_text=True))
|
content = json.loads(response.get_data(as_text=True))
|
||||||
assert 'processed' in content['counts']
|
assert 'sending' in content['counts']
|
||||||
assert 'queued' in content['counts']
|
assert 'delivered' in content['counts']
|
||||||
|
assert 'failed' in content['counts']
|
||||||
assert 'Recipient' in content['notifications']
|
assert 'Recipient' in content['notifications']
|
||||||
|
assert '07123456789' in content['notifications']
|
||||||
assert 'Status' in content['notifications']
|
assert 'Status' in content['notifications']
|
||||||
assert 'Sent by Test User' in content['status']
|
|
||||||
assert job_json['status'] in content['status']
|
assert job_json['status'] in content['status']
|
||||||
|
assert 'Delivered at 11:10' in content['notifications']
|
||||||
|
assert 'Uploaded by Test User on 1 January at 11:09' in content['status']
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_notifications_for_a_service(app_,
|
def test_should_show_notifications_for_a_service(app_,
|
||||||
@@ -90,7 +94,7 @@ def test_should_show_notifications_for_a_service(app_,
|
|||||||
assert notification['to'] in content
|
assert notification['to'] in content
|
||||||
assert notification['status'] in content
|
assert notification['status'] in content
|
||||||
assert notification['template']['name'] in content
|
assert notification['template']['name'] in content
|
||||||
assert 'Download as a CSV file' in content
|
assert 'csv' in content
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string.strip() == 'Activity'
|
assert page.h1.string.strip() == 'Activity'
|
||||||
|
|
||||||
@@ -118,7 +122,7 @@ def test_can_view_only_sms_notifications_for_a_service(app_,
|
|||||||
assert notification['to'] in content
|
assert notification['to'] in content
|
||||||
assert notification['status'] in content
|
assert notification['status'] in content
|
||||||
assert notification['template']['name'] in content
|
assert notification['template']['name'] in content
|
||||||
assert 'Download as a CSV file' in content
|
assert 'csv' in content
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string.strip() == 'Text messages'
|
assert page.h1.string.strip() == 'Text messages'
|
||||||
|
|
||||||
@@ -146,7 +150,7 @@ def test_can_view_only_email_notifications_for_a_service(app_,
|
|||||||
assert notification['to'] in content
|
assert notification['to'] in content
|
||||||
assert notification['status'] in content
|
assert notification['status'] in content
|
||||||
assert notification['template']['name'] in content
|
assert notification['template']['name'] in content
|
||||||
assert 'Download as a CSV file' in content
|
assert 'csv' in content
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string.strip() == 'Emails'
|
assert page.h1.string.strip() == 'Emails'
|
||||||
|
|
||||||
@@ -172,7 +176,7 @@ def test_can_view_successful_notifications_for_a_service(app_,
|
|||||||
assert notification['to'] in content
|
assert notification['to'] in content
|
||||||
assert notification['status'] in content
|
assert notification['status'] in content
|
||||||
assert notification['template']['name'] in content
|
assert notification['template']['name'] in content
|
||||||
assert 'Download as a CSV file' in content
|
assert 'csv' in content
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string.strip() == 'Successful emails and text messages'
|
assert page.h1.string.strip() == 'Successful emails and text messages'
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ def test_can_view_failed_notifications_for_a_service(app_,
|
|||||||
assert notification['to'] in content
|
assert notification['to'] in content
|
||||||
assert notification['status'] in content
|
assert notification['status'] in content
|
||||||
assert notification['template']['name'] in content
|
assert notification['template']['name'] in content
|
||||||
assert 'Download as a CSV file' in content
|
assert 'csv' in content
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.h1.string.strip() == 'Failed emails and text messages'
|
assert page.h1.string.strip() == 'Failed emails and text messages'
|
||||||
|
|
||||||
@@ -264,30 +268,6 @@ def test_should_download_notifications_for_a_service(app_,
|
|||||||
assert 'text/csv' in response.headers['Content-Type']
|
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")
|
@freeze_time("2016-01-01 11:09:00.061258")
|
||||||
def test_should_download_notifications_for_a_job(app_,
|
def test_should_download_notifications_for_a_job(app_,
|
||||||
api_user_active,
|
api_user_active,
|
||||||
@@ -311,4 +291,4 @@ def test_should_download_notifications_for_a_job(app_,
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.get_data(as_text=True) == csv_content
|
assert response.get_data(as_text=True) == csv_content
|
||||||
assert 'text/csv' in response.headers['Content-Type']
|
assert 'text/csv' in response.headers['Content-Type']
|
||||||
assert 'sample template - 01 January at 11:09.csv"' in response.headers['Content-Disposition']
|
assert 'sample template - 1 January at 11:09.csv"' in response.headers['Content-Disposition']
|
||||||
|
|||||||
@@ -794,7 +794,7 @@ def mock_get_job(mocker, api_user_active):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_jobs(mocker, api_user_active):
|
def mock_get_jobs(mocker, api_user_active):
|
||||||
def _get_jobs(service_id):
|
def _get_jobs(service_id, limit_days=None):
|
||||||
data = []
|
data = []
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
job_data = job_json(service_id, api_user_active)
|
job_data = job_json(service_id, api_user_active)
|
||||||
|
|||||||
Reference in New Issue
Block a user