mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Merge branch 'main' of https://github.com/GSA/notifications-admin into 449-one-pager-content-updates
This commit is contained in:
@@ -54,6 +54,7 @@ from app.formatters import (
|
||||
format_datetime_normal,
|
||||
format_datetime_relative,
|
||||
format_datetime_short,
|
||||
format_datetime_short_america,
|
||||
format_day_of_week,
|
||||
format_delta,
|
||||
format_delta_days,
|
||||
@@ -548,6 +549,7 @@ def add_template_filters(application):
|
||||
format_datetime_24h,
|
||||
format_datetime_normal,
|
||||
format_datetime_short,
|
||||
format_datetime_short_america,
|
||||
valid_phone_number,
|
||||
linkable_name,
|
||||
format_date,
|
||||
|
||||
@@ -377,6 +377,32 @@ td.table-empty-message {
|
||||
}
|
||||
}
|
||||
|
||||
.job-table {
|
||||
.usa-table {
|
||||
thead th.file-name {
|
||||
width: 25%;
|
||||
}
|
||||
thead th.template {
|
||||
width: 20%;
|
||||
}
|
||||
thead th.time-sent {
|
||||
width: 30%;
|
||||
}
|
||||
thead th.sender {
|
||||
width: 15%;
|
||||
}
|
||||
thead th.\#-of-recipients {
|
||||
width: 5%;
|
||||
}
|
||||
thead th.report {
|
||||
width: 5%;
|
||||
}
|
||||
th {
|
||||
padding: 0.5rem 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#template-list {
|
||||
max-height: 500px;
|
||||
overflow-y: auto;
|
||||
|
||||
@@ -98,6 +98,28 @@ def format_datetime_short(date):
|
||||
)
|
||||
|
||||
|
||||
def format_datetime_short_america(date):
|
||||
return "{} at {}".format(format_date_numeric_america(date), format_time_12h(date))
|
||||
|
||||
|
||||
def format_date_numeric_america(date):
|
||||
date = parse_naive_dt(date)
|
||||
|
||||
preferred_tz = pytz.timezone(get_user_preferred_timezone())
|
||||
return (
|
||||
date.replace(tzinfo=timezone.utc).astimezone(preferred_tz).strftime("%m-%d-%Y")
|
||||
)
|
||||
|
||||
|
||||
def format_time_12h(date):
|
||||
date = parse_naive_dt(date)
|
||||
|
||||
preferred_tz = pytz.timezone(get_user_preferred_timezone())
|
||||
return (
|
||||
date.replace(tzinfo=timezone.utc).astimezone(preferred_tz).strftime("%I:%M %p")
|
||||
)
|
||||
|
||||
|
||||
def format_datetime_relative(date):
|
||||
return "{} at {} {}".format(
|
||||
get_human_day(date), format_time_24h(date), get_user_preferred_timezone()
|
||||
|
||||
@@ -47,54 +47,31 @@ def service_dashboard(service_id):
|
||||
if not current_user.has_permissions("view_activity"):
|
||||
return redirect(url_for("main.choose_template", service_id=service_id))
|
||||
|
||||
download_availability = []
|
||||
|
||||
notifications = notification_api_client.get_notifications_for_service(
|
||||
service_id=service_id,
|
||||
)["notifications"]
|
||||
|
||||
notificaton_job_ids = [
|
||||
notification["job"]["id"]
|
||||
for notification in notifications
|
||||
if "job" in notification
|
||||
]
|
||||
|
||||
jobs = []
|
||||
|
||||
for notificaton_job_id in notificaton_job_ids:
|
||||
job_data = job_api_client.get_job(service_id, notificaton_job_id)["data"]
|
||||
if job_data:
|
||||
jobs.append(job_data)
|
||||
job_response = job_api_client.get_jobs(service_id)
|
||||
|
||||
service_data_retention_days = 7
|
||||
download_availability = []
|
||||
for job in jobs:
|
||||
message_type = job.get("template_type")
|
||||
if message_type is not None:
|
||||
service_data_retention_days = current_service.get_days_of_retention(
|
||||
message_type
|
||||
)
|
||||
time_left = get_time_left(job["created_at"])
|
||||
download_link = (
|
||||
url_for(
|
||||
".view_job_csv",
|
||||
service_id=current_service.id,
|
||||
job_id=job["id"],
|
||||
jobs = [
|
||||
{
|
||||
"job_id": job["id"],
|
||||
"time_left": get_time_left(job["created_at"]),
|
||||
"download_link": url_for(
|
||||
".view_job_csv", service_id=current_service.id, job_id=job["id"]
|
||||
),
|
||||
)
|
||||
download_availability.append(
|
||||
{
|
||||
"job_id": job["id"],
|
||||
"time_left": time_left,
|
||||
"download_link": download_link,
|
||||
}
|
||||
)
|
||||
"notification_count": job["notification_count"],
|
||||
"created_by": job["created_by"],
|
||||
}
|
||||
for job in job_response["data"]
|
||||
]
|
||||
return render_template(
|
||||
"views/dashboard/dashboard.html",
|
||||
updates_url=url_for(".service_dashboard_updates", service_id=service_id),
|
||||
partials=get_dashboard_partials(service_id),
|
||||
notifications=notifications,
|
||||
download_availability=download_availability,
|
||||
jobs=jobs,
|
||||
service_data_retention_days=service_data_retention_days,
|
||||
)
|
||||
|
||||
|
||||
@@ -29,51 +29,69 @@
|
||||
|
||||
{{ ajax_block(partials, updates_url, 'template-statistics') }}
|
||||
|
||||
<h2 class="margin-top-4 margin-bottom-1">Batched Jobs</h2>
|
||||
|
||||
<h2 class="margin-top-4 margin-bottom-1">Recent Batches</h2>
|
||||
<div class='job-table'>
|
||||
{% call(item, row_number) list_table(
|
||||
notifications,
|
||||
caption="Batched Jobs",
|
||||
caption_visible=False,
|
||||
border_visible=True,
|
||||
empty_message='No batched job messages found  (messages are kept for {} days)'.format(service_data_retention_days)|safe,
|
||||
field_headings=['Template Name','Date/Time', 'Download (CSV) Report'],
|
||||
field_headings_visible=False
|
||||
) %}
|
||||
{% if item.job.original_file_name and item.job.id %}
|
||||
{% call row_heading() %}
|
||||
<a class="usa-link file-list-filename" href="/services/{{ item.service }}/jobs/{{ item.job.id }}">{{ item.job.original_file_name|replace('.csv', '') if item.job.id else '' }}</a>
|
||||
{% endcall %}
|
||||
{% call row_heading() %}
|
||||
{{ item.status|format_notification_status_as_time(
|
||||
item.created_at|format_datetime_short,
|
||||
(item.updated_at or item.created_at)|format_datetime_short)
|
||||
}}
|
||||
{% endcall %}
|
||||
{% call row_heading() %}
|
||||
{% set availability = download_availability|selectattr('job_id', 'equalto', item.job.id)|first %}
|
||||
{% if availability and availability.time_left != "Data no longer available" %}
|
||||
<a class="usa-link file-list-filename" href="{{ availability.download_link[0] }}">{{ "Download" if item.job.original_file_name else '' }}</a>
|
||||
<span>- {{ availability.time_left }}</span>
|
||||
{% elif availability %}
|
||||
<span>{{ availability.time_left }}</span>
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
<table class="usa-table usa-table--borderless width-full">
|
||||
<thead class="table-field-headings">
|
||||
<tr>
|
||||
<th scope="col" class="table-field-heading-first file-name">
|
||||
<span>File name</span>
|
||||
</th>
|
||||
<th scope="col" class="table-field-heading template">
|
||||
<span>Template</span>
|
||||
</th>
|
||||
<th scope="col" class="table-field-heading time-sent">
|
||||
<span>Time sent</span>
|
||||
</th>
|
||||
<th scope="col" class="table-field-heading sender">
|
||||
<span>Sender</span>
|
||||
</th>
|
||||
<th scope="col" class="table-field-heading #-of-recipients">
|
||||
<span># of Recipients</span>
|
||||
</th>
|
||||
<th scope="col" class="table-field-heading report">
|
||||
<span>Report</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for notification in notifications[:5] %}
|
||||
{% if notification %}
|
||||
<tr class="table-row" id="{{ notification.job.id }}">
|
||||
<th class="table-field">
|
||||
{{ notification.job.original_file_name if notification.job.original_file_name else 'Manually entered number'}}
|
||||
<br>
|
||||
<a class="usa-link file-list-filename" href="/services/{{ notification.service }}/jobs/{{ notification.job.id }}">View Batch</a>
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.template.name }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ (notification.updated_at or notification.created_at)| format_datetime_short_america }}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{{ notification.created_by.name }}
|
||||
</th>
|
||||
{% set job_available = jobs|selectattr('job_id', 'equalto', notification.job.id)|first %}
|
||||
<th class="table-field">
|
||||
{{ job_available.notification_count if job_available else ''}}
|
||||
</th>
|
||||
<th class="table-field">
|
||||
{% if job_available and job_available.time_left != "Data no longer available" %}
|
||||
<a class="usa-link file-list-filename" href="{{ job_available.download_link }}">
|
||||
{{ "Download" if job_available.job_id else '' }}</a>
|
||||
<span class="usa-hint">{{ job_available.time_left }}</span>
|
||||
{% elif job_available %}
|
||||
<span>{{ job_available.time_left }}</span>
|
||||
{% endif %}
|
||||
</th>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
{% if show_pagination %}
|
||||
{{ previous_next_navigation(prev_page, next_page) }}
|
||||
{% elif next_page %}
|
||||
<p class="table-show-more-link">
|
||||
Only showing the first 50 messages
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<h2 class="margin-top-4 margin-bottom-1">Usage</h2>
|
||||
<h3 class="margin-bottom-0">Daily</h3>
|
||||
<p class="margin-0">Across all services</p>
|
||||
|
||||
@@ -71,49 +71,32 @@ FAKE_ONE_OFF_NOTIFICATION = {
|
||||
"total": 1,
|
||||
}
|
||||
|
||||
MOCK_ONE_OFF_JOB = {
|
||||
"data": {
|
||||
"api_key": "mocked_api_key",
|
||||
"billable_units": 1,
|
||||
"carrier": "mocked_carrier",
|
||||
"client_reference": "mocked_client_reference",
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"email_address": "mocked_email@example.com",
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"document_download_count": None,
|
||||
"id": "mocked_notification_id",
|
||||
"international": False,
|
||||
"job": {"id": "mocked_job_id", "original_file_name": "mocked_file.txt"},
|
||||
"job_row_number": 0,
|
||||
"key_name": "mocked_key_name",
|
||||
"key_type": "normal",
|
||||
"normalised_to": "+12133166548",
|
||||
"notification_type": "sms",
|
||||
"personalisation": {"phonenumber": "+12133166548"},
|
||||
"phone_prefix": "1",
|
||||
"provider_response": "mocked_provider_response",
|
||||
"rate_multiplier": 1.0,
|
||||
"reference": "mocked_reference",
|
||||
"reply_to_text": "mocked_reply_text",
|
||||
"sent_at": "2024-01-04T20:43:53+00:00",
|
||||
"sent_by": "mocked_sender",
|
||||
"service": "mocked_service_id",
|
||||
"status": "sending",
|
||||
"template": {
|
||||
"content": "((day of week)) and ((fave color))",
|
||||
"id": "bd9caa7e-00ee-4c5a-839e-10ae1a7e6f73",
|
||||
"name": "personalized",
|
||||
"redact_personalisation": False,
|
||||
"subject": None,
|
||||
MOCK_JOBS = {
|
||||
"data": [
|
||||
{
|
||||
"archived": False,
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"id": "mocked_notification_id",
|
||||
"job_status": "finished",
|
||||
"notification_count": 1,
|
||||
"original_file_name": "mocked_file.csv",
|
||||
"processing_finished": "2024-01-25T23:02:25+00:00",
|
||||
"processing_started": "2024-01-25T23:02:24+00:00",
|
||||
"scheduled_for": None,
|
||||
"service": "21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3",
|
||||
"service_name": {"name": "Mock Texting Service"},
|
||||
"statistics": [{"count": 1, "status": "sending"}],
|
||||
"template": "6a456418-498c-4c86-b0cd-9403c14a216c",
|
||||
"template_name": "Mock Template Name",
|
||||
"template_type": "sms",
|
||||
"version": 1,
|
||||
},
|
||||
"to": "+12133166548",
|
||||
"updated_at": "2024-01-04T20:43:53+00:00",
|
||||
}
|
||||
"template_version": 3,
|
||||
"updated_at": "2024-01-25T23:02:25+00:00",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +292,7 @@ def test_accepting_invite_removes_invite_from_session(
|
||||
sample_invite["email_address"] = user["email_address"]
|
||||
|
||||
client_request.login(user)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -725,7 +708,7 @@ def test_new_invited_user_verifies_and_added_to_service(
|
||||
token="thisisnotarealtoken",
|
||||
_expected_redirect=url_for("main.register_from_invite"),
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
|
||||
@@ -85,49 +85,32 @@ FAKE_ONE_OFF_NOTIFICATION = {
|
||||
"total": 1,
|
||||
}
|
||||
|
||||
MOCK_ONE_OFF_JOB = {
|
||||
"data": {
|
||||
"api_key": "mocked_api_key",
|
||||
"billable_units": 1,
|
||||
"carrier": "mocked_carrier",
|
||||
"client_reference": "mocked_client_reference",
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"email_address": "mocked_email@example.com",
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"document_download_count": None,
|
||||
"id": "mocked_notification_id",
|
||||
"international": False,
|
||||
"job": {"id": "mocked_job_id", "original_file_name": "mocked_file.txt"},
|
||||
"job_row_number": 0,
|
||||
"key_name": "mocked_key_name",
|
||||
"key_type": "normal",
|
||||
"normalised_to": "+12133166548",
|
||||
"notification_type": "sms",
|
||||
"personalisation": {"phonenumber": "+12133166548"},
|
||||
"phone_prefix": "1",
|
||||
"provider_response": "mocked_provider_response",
|
||||
"rate_multiplier": 1.0,
|
||||
"reference": "mocked_reference",
|
||||
"reply_to_text": "mocked_reply_text",
|
||||
"sent_at": "2024-01-04T20:43:53+00:00",
|
||||
"sent_by": "mocked_sender",
|
||||
"service": "mocked_service_id",
|
||||
"status": "sending",
|
||||
"template": {
|
||||
"content": "((day of week)) and ((fave color))",
|
||||
"id": "bd9caa7e-00ee-4c5a-839e-10ae1a7e6f73",
|
||||
"name": "personalized",
|
||||
"redact_personalisation": False,
|
||||
"subject": None,
|
||||
MOCK_JOBS = {
|
||||
"data": [
|
||||
{
|
||||
"archived": False,
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"id": "mocked_notification_id",
|
||||
"job_status": "finished",
|
||||
"notification_count": 1,
|
||||
"original_file_name": "mocked_file.csv",
|
||||
"processing_finished": "2024-01-25T23:02:25+00:00",
|
||||
"processing_started": "2024-01-25T23:02:24+00:00",
|
||||
"scheduled_for": None,
|
||||
"service": "21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3",
|
||||
"service_name": {"name": "Mock Texting Service"},
|
||||
"statistics": [{"count": 1, "status": "sending"}],
|
||||
"template": "6a456418-498c-4c86-b0cd-9403c14a216c",
|
||||
"template_name": "Mock Template Name",
|
||||
"template_type": "sms",
|
||||
"version": 1,
|
||||
},
|
||||
"to": "+12133166548",
|
||||
"updated_at": "2024-01-04T20:43:53+00:00",
|
||||
}
|
||||
"template_version": 3,
|
||||
"updated_at": "2024-01-25T23:02:25+00:00",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
stub_template_stats = [
|
||||
@@ -218,7 +201,7 @@ def test_get_started(
|
||||
"app.template_statistics_client.get_template_statistics_for_service",
|
||||
return_value=copy.deepcopy(stub_template_stats),
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -248,7 +231,7 @@ def test_get_started_is_hidden_once_templates_exist(
|
||||
"app.template_statistics_client.get_template_statistics_for_service",
|
||||
return_value=copy.deepcopy(stub_template_stats),
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -275,7 +258,7 @@ def test_inbound_messages_not_visible_to_service_without_permissions(
|
||||
mock_get_inbound_sms_summary,
|
||||
):
|
||||
service_one["permissions"] = []
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -303,7 +286,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages(
|
||||
mock_get_inbound_sms_summary,
|
||||
):
|
||||
service_one["permissions"] = ["inbound_sms"]
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
||||
@@ -312,7 +294,8 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages(
|
||||
"main.service_dashboard",
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID)
|
||||
mock_get_jobs.assert_called_with(SERVICE_ONE_ID)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
banner = page.select("a.banner-dashboard")[1]
|
||||
assert (
|
||||
normalize_spaces(banner.text)
|
||||
@@ -335,7 +318,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages(
|
||||
mock_get_inbound_sms_summary_with_no_messages,
|
||||
):
|
||||
service_one["permissions"] = ["inbound_sms"]
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
||||
@@ -344,7 +326,8 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages(
|
||||
"main.service_dashboard",
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID)
|
||||
mock_get_jobs.assert_called_with(SERVICE_ONE_ID)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
banner = page.select("a.banner-dashboard")[1]
|
||||
assert normalize_spaces(banner.text) == "0 text messages received"
|
||||
assert banner["href"] == url_for("main.inbox", service_id=SERVICE_ONE_ID)
|
||||
@@ -585,7 +568,7 @@ def test_should_show_recent_templates_on_dashboard(
|
||||
"app.template_statistics_client.get_template_statistics_for_service",
|
||||
return_value=copy.deepcopy(stub_template_stats),
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -642,7 +625,7 @@ def test_should_not_show_recent_templates_on_dashboard_if_only_one_template_used
|
||||
"app.template_statistics_client.get_template_statistics_for_service",
|
||||
return_value=stats,
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -782,7 +765,6 @@ def test_should_show_upcoming_jobs_on_dashboard(
|
||||
mock_get_free_sms_fragment_limit,
|
||||
mock_get_inbound_sms_summary,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
||||
@@ -792,7 +774,8 @@ def test_should_show_upcoming_jobs_on_dashboard(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
|
||||
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID)
|
||||
mock_get_jobs.assert_called_with(SERVICE_ONE_ID)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
mock_get_scheduled_job_stats.assert_called_once_with(SERVICE_ONE_ID)
|
||||
|
||||
assert normalize_spaces(page.select_one("main h2").text) == ("In the next few days")
|
||||
@@ -824,7 +807,7 @@ def test_should_not_show_upcoming_jobs_on_dashboard_if_count_is_0(
|
||||
"soonest_scheduled_for": None,
|
||||
},
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -850,7 +833,7 @@ def test_should_not_show_upcoming_jobs_on_dashboard_if_service_has_no_jobs(
|
||||
mock_get_free_sms_fragment_limit,
|
||||
mock_get_inbound_sms_summary,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -904,7 +887,7 @@ def test_correct_font_size_for_big_numbers(
|
||||
service_one["permissions"] = permissions
|
||||
|
||||
mocker.patch("app.main.views.dashboard.get_dashboard_totals", return_value=totals)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -938,7 +921,6 @@ def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page(
|
||||
mock_get_free_sms_fragment_limit,
|
||||
mock_get_inbound_sms_summary,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=FAKE_ONE_OFF_NOTIFICATION,
|
||||
@@ -947,7 +929,8 @@ def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page(
|
||||
"main.service_dashboard",
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
mock_get_jobs.assert_called_once_with(SERVICE_ONE_ID)
|
||||
mock_get_jobs.assert_called_with(SERVICE_ONE_ID)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
for filename in {
|
||||
"export 1/1/2016.xls",
|
||||
"all email addresses.xlsx",
|
||||
@@ -1209,7 +1192,7 @@ def test_menu_send_messages(
|
||||
):
|
||||
service_one["permissions"] = ["email", "sms"]
|
||||
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1246,7 +1229,7 @@ def test_menu_manage_service(
|
||||
mock_get_inbound_sms_summary,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1283,7 +1266,7 @@ def test_menu_main_settings(
|
||||
mock_get_inbound_sms_summary,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1319,7 +1302,7 @@ def test_menu_manage_api_keys(
|
||||
mock_get_inbound_sms_summary,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1359,7 +1342,7 @@ def test_menu_all_services_for_platform_admin_user(
|
||||
mock_get_inbound_sms_summary,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1404,7 +1387,7 @@ def test_route_for_service_permissions(
|
||||
mocker.patch(
|
||||
"app.service_api_client.get_global_notification_count", side_effect=_get
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1460,7 +1443,7 @@ def test_service_dashboard_updates_gets_dashboard_totals(
|
||||
"sms": {"requested": 456, "delivered": 0, "failed": 0},
|
||||
},
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1586,7 +1569,7 @@ def test_org_breadcrumbs_do_not_show_if_service_has_no_org(
|
||||
mock_get_annual_usage_for_service,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1653,7 +1636,7 @@ def test_org_breadcrumbs_show_if_user_is_a_member_of_the_services_org(
|
||||
id_=ORGANISATION_ID,
|
||||
),
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1689,7 +1672,7 @@ def test_org_breadcrumbs_do_not_show_if_user_is_a_member_of_the_services_org_but
|
||||
)
|
||||
mocker.patch("app.models.service.Organization")
|
||||
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
@@ -1727,7 +1710,7 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin(
|
||||
),
|
||||
)
|
||||
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
@@ -1763,7 +1746,7 @@ def test_breadcrumb_shows_if_service_is_suspended(
|
||||
"app.service_api_client.get_service", return_value={"data": service_one_json}
|
||||
)
|
||||
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
@@ -1797,7 +1780,7 @@ def test_service_dashboard_shows_usage(
|
||||
"count": 500,
|
||||
},
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
@@ -1840,7 +1823,7 @@ def test_service_dashboard_shows_free_allowance(
|
||||
}
|
||||
],
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
@@ -1864,7 +1847,7 @@ def test_service_dashboard_shows_batched_jobs(
|
||||
mock_get_annual_usage_for_service,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
):
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
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,
|
||||
|
||||
@@ -57,49 +57,32 @@ FAKE_ONE_OFF_NOTIFICATION = {
|
||||
"total": 1,
|
||||
}
|
||||
|
||||
MOCK_ONE_OFF_JOB = {
|
||||
"data": {
|
||||
"api_key": "mocked_api_key",
|
||||
"billable_units": 1,
|
||||
"carrier": "mocked_carrier",
|
||||
"client_reference": "mocked_client_reference",
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"email_address": "mocked_email@example.com",
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"document_download_count": None,
|
||||
"id": "mocked_notification_id",
|
||||
"international": False,
|
||||
"job": {"id": "mocked_job_id", "original_file_name": "mocked_file.txt"},
|
||||
"job_row_number": 0,
|
||||
"key_name": "mocked_key_name",
|
||||
"key_type": "normal",
|
||||
"normalised_to": "+12133166548",
|
||||
"notification_type": "sms",
|
||||
"personalisation": {"phonenumber": "+12133166548"},
|
||||
"phone_prefix": "1",
|
||||
"provider_response": "mocked_provider_response",
|
||||
"rate_multiplier": 1.0,
|
||||
"reference": "mocked_reference",
|
||||
"reply_to_text": "mocked_reply_text",
|
||||
"sent_at": "2024-01-04T20:43:53+00:00",
|
||||
"sent_by": "mocked_sender",
|
||||
"service": "mocked_service_id",
|
||||
"status": "sending",
|
||||
"template": {
|
||||
"content": "((day of week)) and ((fave color))",
|
||||
"id": "bd9caa7e-00ee-4c5a-839e-10ae1a7e6f73",
|
||||
"name": "personalized",
|
||||
"redact_personalisation": False,
|
||||
"subject": None,
|
||||
MOCK_JOBS = {
|
||||
"data": [
|
||||
{
|
||||
"archived": False,
|
||||
"created_at": "2024-01-04T20:43:52+00:00",
|
||||
"created_by": {
|
||||
"id": "mocked_user_id",
|
||||
"name": "mocked_user",
|
||||
},
|
||||
"id": "mocked_notification_id",
|
||||
"job_status": "finished",
|
||||
"notification_count": 1,
|
||||
"original_file_name": "mocked_file.csv",
|
||||
"processing_finished": "2024-01-25T23:02:25+00:00",
|
||||
"processing_started": "2024-01-25T23:02:24+00:00",
|
||||
"scheduled_for": None,
|
||||
"service": "21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3",
|
||||
"service_name": {"name": "Mock Texting Service"},
|
||||
"statistics": [{"count": 1, "status": "sending"}],
|
||||
"template": "6a456418-498c-4c86-b0cd-9403c14a216c",
|
||||
"template_name": "Mock Template Name",
|
||||
"template_type": "sms",
|
||||
"version": 1,
|
||||
},
|
||||
"to": "+12133166548",
|
||||
"updated_at": "2024-01-04T20:43:53+00:00",
|
||||
}
|
||||
"template_version": 3,
|
||||
"updated_at": "2024-01-25T23:02:25+00:00",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +122,7 @@ def test_sign_out_user(
|
||||
with client_request.session_transaction() as session:
|
||||
assert session.get("user_id") is not None
|
||||
# Check we are logged in
|
||||
mocker.patch("app.job_api_client.get_job", return_value=MOCK_ONE_OFF_JOB)
|
||||
mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS)
|
||||
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
|
||||
Reference in New Issue
Block a user