mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 20:08:26 -04:00
Fixed KeyError on processing_finished and removed notification api call
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import calendar
|
import calendar
|
||||||
from collections import defaultdict
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
@@ -13,7 +12,6 @@ from app import (
|
|||||||
billing_api_client,
|
billing_api_client,
|
||||||
current_service,
|
current_service,
|
||||||
job_api_client,
|
job_api_client,
|
||||||
notification_api_client,
|
|
||||||
service_api_client,
|
service_api_client,
|
||||||
socketio,
|
socketio,
|
||||||
template_statistics_client,
|
template_statistics_client,
|
||||||
@@ -83,18 +81,9 @@ def service_dashboard(service_id):
|
|||||||
return redirect(url_for("main.choose_template", service_id=service_id))
|
return redirect(url_for("main.choose_template", service_id=service_id))
|
||||||
|
|
||||||
job_response = job_api_client.get_jobs(service_id)["data"]
|
job_response = job_api_client.get_jobs(service_id)["data"]
|
||||||
notifications_response = notification_api_client.get_notifications_for_service(
|
|
||||||
service_id
|
|
||||||
)["notifications"]
|
|
||||||
service_data_retention_days = 7
|
service_data_retention_days = 7
|
||||||
|
|
||||||
aggregate_notifications_by_job = defaultdict(list)
|
jobs = [
|
||||||
for notification in notifications_response:
|
|
||||||
job_id = notification.get("job", {}).get("id", None)
|
|
||||||
if job_id:
|
|
||||||
aggregate_notifications_by_job[job_id].append(notification)
|
|
||||||
|
|
||||||
job_and_notifications = [
|
|
||||||
{
|
{
|
||||||
"job_id": job["id"],
|
"job_id": job["id"],
|
||||||
"time_left": get_time_left(job["created_at"]),
|
"time_left": get_time_left(job["created_at"]),
|
||||||
@@ -105,20 +94,20 @@ def service_dashboard(service_id):
|
|||||||
".view_job", service_id=current_service.id, job_id=job["id"]
|
".view_job", service_id=current_service.id, job_id=job["id"]
|
||||||
),
|
),
|
||||||
"created_at": job["created_at"],
|
"created_at": job["created_at"],
|
||||||
"processing_finished": job["processing_finished"],
|
"processing_finished": job.get("processing_finished"),
|
||||||
"processing_started": job["processing_started"],
|
"processing_started": job.get("processing_started"),
|
||||||
"notification_count": job["notification_count"],
|
"notification_count": job["notification_count"],
|
||||||
"created_by": job["created_by"],
|
"created_by": job["created_by"],
|
||||||
"notifications": aggregate_notifications_by_job.get(job["id"], []),
|
"template_name": job["template_name"],
|
||||||
|
"original_file_name": job["original_file_name"],
|
||||||
}
|
}
|
||||||
for job in job_response
|
for job in job_response
|
||||||
if aggregate_notifications_by_job.get(job["id"], [])
|
|
||||||
]
|
]
|
||||||
return render_template(
|
return render_template(
|
||||||
"views/dashboard/dashboard.html",
|
"views/dashboard/dashboard.html",
|
||||||
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
|
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
|
||||||
partials=get_dashboard_partials(service_id),
|
partials=get_dashboard_partials(service_id),
|
||||||
job_and_notifications=job_and_notifications,
|
jobs=jobs,
|
||||||
service_data_retention_days=service_data_retention_days,
|
service_data_retention_days=service_data_retention_days,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -55,31 +55,30 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% if job_and_notifications %}
|
{% if jobs %}
|
||||||
{% for job in job_and_notifications[:5] %}
|
{% for job in jobs[:5] %}
|
||||||
{% if job.job_id and job.notifications %}
|
|
||||||
{% set notification = job.notifications[0] %}
|
{% set notification = job.notifications[0] %}
|
||||||
<tr class="table-row" id="{{ job.job_id }}">
|
<tr class="table-row" id="{{ job.job_id }}">
|
||||||
<td class="table-field file-name">
|
<td class="table-field file-name">
|
||||||
{{ notification.job.original_file_name[:12] if notification.job.original_file_name else 'Manually entered number'}}
|
{{ job.original_file_name[:12] if job.original_file_name else 'Manually entered number'}}
|
||||||
<br>
|
<br>
|
||||||
<a class="usa-link file-list-filename" href="{{ job.view_job_link }}">View Batch</a>
|
<a class="usa-link file-list-filename" href="{{ job.view_job_link }}">View Batch</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field template">
|
<td class="table-field template">
|
||||||
{{ notification.template.name }}
|
{{ job.template_name }}
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field time-sent">
|
<td class="table-field time-sent">
|
||||||
{{ (job.processing_finished if job.processing_finished else job.processing_started
|
{{ (job.processing_finished if job.processing_finished else job.processing_started
|
||||||
if job.processing_started else job.created_at)|format_datetime_table }}
|
if job.processing_started else job.created_at)|format_datetime_table }}
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field sender">
|
<td class="table-field sender">
|
||||||
{{ notification.created_by.name }}
|
{{ job.created_by.name }}
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field count-of-recipients">
|
<td class="table-field count-of-recipients">
|
||||||
{{ job.notification_count}}
|
{{ job.notification_count}}
|
||||||
</td>
|
</td>
|
||||||
<td class="table-field report">
|
<td class="table-field report">
|
||||||
{% if notification and job.time_left != "Data no longer available" %}
|
{% if job.time_left != "Data no longer available" %}
|
||||||
<a class="usa-link file-list-filename" href="{{ job.download_link }}">Download</a>
|
<a class="usa-link file-list-filename" href="{{ job.download_link }}">Download</a>
|
||||||
<span class="usa-hint">{{ job.time_left }}</span>
|
<span class="usa-hint">{{ job.time_left }}</span>
|
||||||
{% elif job %}
|
{% elif job %}
|
||||||
@@ -87,7 +86,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr class="table-row">
|
<tr class="table-row">
|
||||||
|
|||||||
@@ -305,10 +305,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages(
|
|||||||
mock_get_inbound_sms_summary,
|
mock_get_inbound_sms_summary,
|
||||||
):
|
):
|
||||||
service_one["permissions"] = ["inbound_sms"]
|
service_one["permissions"] = ["inbound_sms"]
|
||||||
mocker.patch(
|
|
||||||
"app.notification_api_client.get_notifications_for_service",
|
|
||||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
"main.service_dashboard",
|
"main.service_dashboard",
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
@@ -337,10 +333,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages(
|
|||||||
mock_get_inbound_sms_summary_with_no_messages,
|
mock_get_inbound_sms_summary_with_no_messages,
|
||||||
):
|
):
|
||||||
service_one["permissions"] = ["inbound_sms"]
|
service_one["permissions"] = ["inbound_sms"]
|
||||||
mocker.patch(
|
|
||||||
"app.notification_api_client.get_notifications_for_service",
|
|
||||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
"main.service_dashboard",
|
"main.service_dashboard",
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
@@ -839,10 +831,6 @@ def test_should_not_show_upcoming_jobs_on_dashboard_if_count_is_0(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||||
mocker.patch(
|
|
||||||
"app.notification_api_client.get_notifications_for_service",
|
|
||||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
"main.service_dashboard",
|
"main.service_dashboard",
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
@@ -919,10 +907,6 @@ def test_correct_font_size_for_big_numbers(
|
|||||||
|
|
||||||
mocker.patch("app.main.views.dashboard.get_dashboard_totals", return_value=totals)
|
mocker.patch("app.main.views.dashboard.get_dashboard_totals", return_value=totals)
|
||||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||||
mocker.patch(
|
|
||||||
"app.notification_api_client.get_notifications_for_service",
|
|
||||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
"main.service_dashboard",
|
"main.service_dashboard",
|
||||||
service_id=service_one["id"],
|
service_id=service_one["id"],
|
||||||
@@ -952,10 +936,6 @@ def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page(
|
|||||||
mock_get_free_sms_fragment_limit,
|
mock_get_free_sms_fragment_limit,
|
||||||
mock_get_inbound_sms_summary,
|
mock_get_inbound_sms_summary,
|
||||||
):
|
):
|
||||||
mocker.patch(
|
|
||||||
"app.notification_api_client.get_notifications_for_service",
|
|
||||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
"main.service_dashboard",
|
"main.service_dashboard",
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
|
|||||||
Reference in New Issue
Block a user