mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Bugfix/polling improvements - Pointing polling to new backend endpoint designed for status only (#2949)
* Optimizing polling * Fixed formatting issue * Pointed new endpoint to new backend polling endpoint * Missed a unit test update * Fixed flake issue
This commit is contained in:
@@ -12,8 +12,6 @@ import json
|
||||
|
||||
import pytest
|
||||
|
||||
from tests import job_json, user_json
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("delivered", "failed", "pending", "finished", "js_should_update_notifications", "reason"),
|
||||
@@ -46,25 +44,14 @@ def test_poll_status_notification_update_logic(
|
||||
job is finished (regardless of count)
|
||||
"""
|
||||
total = delivered + failed + pending
|
||||
job_status = "finished" if finished else "sending"
|
||||
|
||||
mock_job = mocker.patch("app.job_api_client.get_job")
|
||||
mock_job.return_value = {
|
||||
"data": {
|
||||
**job_json(
|
||||
service_one["id"],
|
||||
created_by=user_json(),
|
||||
job_id=fake_uuid,
|
||||
job_status=job_status,
|
||||
notification_count=total,
|
||||
notifications_requested=total,
|
||||
),
|
||||
"statistics": [
|
||||
{"status": "delivered", "count": delivered},
|
||||
{"status": "failed", "count": failed},
|
||||
{"status": "pending", "count": pending},
|
||||
],
|
||||
}
|
||||
mock_job_status = mocker.patch("app.job_api_client.get_job_status")
|
||||
mock_job_status.return_value = {
|
||||
"sent_count": delivered,
|
||||
"failed_count": failed,
|
||||
"pending_count": pending,
|
||||
"total_count": total,
|
||||
"processing_finished": finished,
|
||||
}
|
||||
|
||||
response = client_request.get_response(
|
||||
@@ -107,23 +94,13 @@ def test_poll_status_provides_required_fields(
|
||||
fake_uuid,
|
||||
):
|
||||
"""Verify poll status endpoint returns all fields needed for notification update logic."""
|
||||
mock_job = mocker.patch("app.job_api_client.get_job")
|
||||
mock_job.return_value = {
|
||||
"data": {
|
||||
**job_json(
|
||||
service_one["id"],
|
||||
created_by=user_json(),
|
||||
job_id=fake_uuid,
|
||||
job_status="sending",
|
||||
notification_count=25,
|
||||
notifications_requested=25,
|
||||
),
|
||||
"statistics": [
|
||||
{"status": "delivered", "count": 15},
|
||||
{"status": "failed", "count": 5},
|
||||
{"status": "pending", "count": 5},
|
||||
],
|
||||
}
|
||||
mock_job_status = mocker.patch("app.job_api_client.get_job_status")
|
||||
mock_job_status.return_value = {
|
||||
"sent_count": 15,
|
||||
"failed_count": 5,
|
||||
"pending_count": 5,
|
||||
"total_count": 25,
|
||||
"processing_finished": False,
|
||||
}
|
||||
|
||||
response = client_request.get_response(
|
||||
|
||||
@@ -510,23 +510,13 @@ def test_poll_status_endpoint(
|
||||
fake_uuid,
|
||||
):
|
||||
"""Test that the poll status endpoint returns only required data without notifications"""
|
||||
mock_job = mocker.patch("app.job_api_client.get_job")
|
||||
mock_job.return_value = {
|
||||
"data": {
|
||||
**job_json(
|
||||
service_one["id"],
|
||||
created_by=user_json(),
|
||||
job_id=fake_uuid,
|
||||
job_status="finished",
|
||||
notification_count=100,
|
||||
notifications_requested=100,
|
||||
),
|
||||
"statistics": [
|
||||
{"status": "delivered", "count": 90},
|
||||
{"status": "failed", "count": 10},
|
||||
{"status": "pending", "count": 0},
|
||||
],
|
||||
}
|
||||
mock_job_status = mocker.patch("app.job_api_client.get_job_status")
|
||||
mock_job_status.return_value = {
|
||||
"sent_count": 90,
|
||||
"failed_count": 10,
|
||||
"pending_count": 0,
|
||||
"total_count": 100,
|
||||
"processing_finished": True,
|
||||
}
|
||||
|
||||
response = client_request.get_response(
|
||||
@@ -563,19 +553,13 @@ def test_poll_status_with_zero_notifications(
|
||||
fake_uuid,
|
||||
):
|
||||
"""Test poll status endpoint handles edge case of no notifications"""
|
||||
mock_job = mocker.patch("app.job_api_client.get_job")
|
||||
mock_job.return_value = {
|
||||
"data": {
|
||||
**job_json(
|
||||
service_one["id"],
|
||||
created_by=user_json(),
|
||||
job_id=fake_uuid,
|
||||
job_status="pending",
|
||||
notification_count=0,
|
||||
notifications_requested=0,
|
||||
),
|
||||
"statistics": [],
|
||||
}
|
||||
mock_job_status = mocker.patch("app.job_api_client.get_job_status")
|
||||
mock_job_status.return_value = {
|
||||
"sent_count": 0,
|
||||
"failed_count": 0,
|
||||
"pending_count": 0,
|
||||
"total_count": 0,
|
||||
"processing_finished": True,
|
||||
}
|
||||
|
||||
response = client_request.get_response(
|
||||
@@ -588,9 +572,7 @@ def test_poll_status_with_zero_notifications(
|
||||
data = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert data["total_count"] == 0
|
||||
assert (
|
||||
data["finished"] is True
|
||||
)
|
||||
assert data["finished"] is True
|
||||
|
||||
|
||||
def test_poll_status_endpoint_does_not_query_notifications_table(
|
||||
@@ -602,23 +584,13 @@ def test_poll_status_endpoint_does_not_query_notifications_table(
|
||||
fake_uuid,
|
||||
):
|
||||
"""Critical regression test: ensure poll status endpoint never queries notifications"""
|
||||
mock_job = mocker.patch("app.job_api_client.get_job")
|
||||
mock_job.return_value = {
|
||||
"data": {
|
||||
**job_json(
|
||||
service_one["id"],
|
||||
created_by=user_json(),
|
||||
job_id=fake_uuid,
|
||||
job_status="sending",
|
||||
notification_count=500,
|
||||
notifications_requested=500,
|
||||
),
|
||||
"statistics": [
|
||||
{"status": "delivered", "count": 300},
|
||||
{"status": "failed", "count": 50},
|
||||
{"status": "pending", "count": 150},
|
||||
],
|
||||
}
|
||||
mock_job_status = mocker.patch("app.job_api_client.get_job_status")
|
||||
mock_job_status.return_value = {
|
||||
"sent_count": 300,
|
||||
"failed_count": 50,
|
||||
"pending_count": 150,
|
||||
"total_count": 500,
|
||||
"processing_finished": False,
|
||||
}
|
||||
|
||||
mock_get_notifications = mocker.patch(
|
||||
@@ -639,3 +611,6 @@ def test_poll_status_endpoint_does_not_query_notifications_table(
|
||||
data = json.loads(response.get_data(as_text=True))
|
||||
assert data["total_count"] == 500
|
||||
assert data["sent_count"] == 300
|
||||
assert data["failed_count"] == 50
|
||||
assert data["pending_count"] == 150
|
||||
assert data["finished"] is False
|
||||
|
||||
Reference in New Issue
Block a user