Merge branch 'main' of https://github.com/GSA/notifications-admin into 1544-data-viz-total-message-allowance

# Conflicts:
#	app/main/views/dashboard.py
#	package-lock.json
#	package.json
This commit is contained in:
Jonathan Bobel
2024-07-04 13:25:03 -04:00
52 changed files with 2218 additions and 2585 deletions

View File

@@ -228,12 +228,18 @@ def test_can_show_notifications_if_data_retention_not_available(
url_for,
".download_notifications_csv",
message_type=None,
number_of_days="seven_day",
),
),
(
create_active_user_with_permissions(),
{"status": "failed"},
partial(url_for, ".download_notifications_csv", status="failed"),
partial(
url_for,
".download_notifications_csv",
status="failed",
number_of_days="seven_day",
),
),
(
create_active_user_with_permissions(),
@@ -242,15 +248,13 @@ def test_can_show_notifications_if_data_retention_not_available(
url_for,
".download_notifications_csv",
message_type="sms",
number_of_days="seven_day",
),
),
(
create_active_user_view_permissions(),
{},
partial(
url_for,
".download_notifications_csv",
),
partial(url_for, ".download_notifications_csv", number_of_days="seven_day"),
),
(
create_active_caseworking_user(),

View File

@@ -4,10 +4,10 @@ from datetime import datetime
import pytest
from flask import Flask, url_for
from flask_socketio import SocketIOTestClient
from flask_socketio import SocketIO, SocketIOTestClient
from freezegun import freeze_time
from app import create_app, socketio
from app import create_app
from app.main.views.dashboard import (
aggregate_notifications_stats,
aggregate_status_types,
@@ -15,6 +15,8 @@ from app.main.views.dashboard import (
format_monthly_stats_to_list,
get_dashboard_totals,
get_tuples_of_financial_years,
handle_fetch_daily_stats,
handle_fetch_daily_stats_by_user,
)
from tests import (
organization_json,
@@ -26,6 +28,7 @@ from tests.conftest import (
ORGANISATION_ID,
SERVICE_ONE_ID,
SERVICE_TWO_ID,
USER_ONE_ID,
create_active_caseworking_user,
create_active_user_view_permissions,
normalize_spaces,
@@ -1868,7 +1871,6 @@ def test_service_dashboard_shows_batched_jobs(
rows = job_table_body.find_all("tbody")[0].find_all("tr")
# # Check if the "Job" table exists
assert job_table_body is not None
assert len(rows) == 1
@@ -1878,6 +1880,9 @@ def test_service_dashboard_shows_batched_jobs(
def app_with_socketio():
app = Flask("app")
create_app(app)
socketio = SocketIO(app)
socketio.on_event("fetch_daily_stats", handle_fetch_daily_stats)
socketio.on_event("fetch_daily_stats_by_user", handle_fetch_daily_stats_by_user)
return app, socketio
@@ -1897,7 +1902,11 @@ def app_with_socketio():
],
)
def test_fetch_daily_stats(
app_with_socketio, mocker, service_id, date_range, expected_call_args
app_with_socketio,
mocker,
service_id,
date_range,
expected_call_args,
):
app, socketio = app_with_socketio
@@ -1914,15 +1923,23 @@ def test_fetch_daily_stats(
},
},
)
with app.test_client() as client:
with client.session_transaction() as sess:
sess['service_id'] = service_id
client = SocketIOTestClient(app, socketio)
try:
connected = client.is_connected()
socketio_client = SocketIOTestClient(app, socketio, flask_test_client=client)
connected = socketio_client.is_connected()
assert connected, "Client should be connected"
client.emit("fetch_daily_stats", service_id)
socketio_client.emit('fetch_daily_stats')
received = socketio_client.get_received()
received = client.get_received()
mock_service_api.assert_called_once_with(
expected_call_args["service_id"],
start_date=expected_call_args["start_date"],
days=expected_call_args["days"],
)
assert received, "Should receive a response message"
assert received[0]["name"] == "daily_stats_update"
assert received[0]["args"][0] == {
@@ -1932,12 +1949,78 @@ def test_fetch_daily_stats(
},
}
socketio_client.disconnect()
disconnected = not socketio_client.is_connected()
assert disconnected, "Client should be disconnected"
@pytest.mark.parametrize(
("service_id", "user_id", "date_range", "expected_call_args", "user"),
[
(
SERVICE_ONE_ID,
USER_ONE_ID,
{"start_date": "2024-01-01", "days": 7},
{"service_id": SERVICE_ONE_ID, "user_id": USER_ONE_ID, "start_date": "2024-01-01", "days": 7},
{"id": USER_ONE_ID, "name": "Test User"}
),
],
)
def test_fetch_daily_stats_by_user(
app_with_socketio,
mocker,
service_id,
user_id,
date_range,
expected_call_args,
user,
):
app, socketio = app_with_socketio
mocker.patch(
"app.main.views.dashboard.get_stats_date_range", return_value=date_range
)
mock_service_api = mocker.patch(
"app.service_api_client.get_user_service_notification_statistics_by_day",
return_value={
date_range["start_date"]: {
"email": {"delivered": 0, "failure": 0, "requested": 0},
"sms": {"delivered": 0, "failure": 1, "requested": 1},
},
},
)
mocker.patch("app.user_api_client.get_user", return_value=user)
with app.test_client() as client:
with client.session_transaction() as sess:
sess['service_id'] = service_id
sess['user_id'] = user_id
socketio_client = SocketIOTestClient(app, socketio, flask_test_client=client)
connected = socketio_client.is_connected()
assert connected, "Client should be connected"
socketio_client.emit('fetch_daily_stats_by_user')
received = socketio_client.get_received()
mock_service_api.assert_called_once_with(
service_id,
expected_call_args["service_id"],
expected_call_args["user_id"],
start_date=expected_call_args["start_date"],
days=expected_call_args["days"],
)
finally:
client.disconnect()
disconnected = not client.is_connected()
assert received, "Should receive a response message"
assert received[0]["name"] == "daily_stats_by_user_update"
assert received[0]["args"][0] == {
date_range["start_date"]: {
"email": {"delivered": 0, "failure": 0, "requested": 0},
"sms": {"delivered": 0, "failure": 1, "requested": 1},
},
}
socketio_client.disconnect()
disconnected = not socketio_client.is_connected()
assert disconnected, "Client should be disconnected"

View File

@@ -530,10 +530,10 @@ def test_should_200_for_check_tour_notification(
assert normalize_spaces(page.select(".banner-tour .heading-medium")[0].text) == (
"Try sending yourself this example"
)
selected_hint = page.select(".banner-tour .grid-row")[1]
selected_hint = page.select(".banner-tour .grid-row")[2]
selected_hint_text = normalize_spaces(selected_hint.select(".usa-body")[0].text)
assert "greyed-out-step" not in selected_hint["class"]
assert selected_hint_text == "The template pulls in the data you provide"
assert selected_hint_text == "Notify delivers the message"
assert normalize_spaces(page.select(".sms-message-recipient")[0].text) == (
"To: 202-867-5303"
@@ -544,9 +544,10 @@ def test_should_200_for_check_tour_notification(
# post to send_notification keeps help argument
assert page.form.attrs["action"] == url_for(
"main.preview_notification",
"main.send_notification",
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
help=3,
)