mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-10 15:13:40 -05:00
Merge pull request #1797 from GSA/Logging_the_job_information_that_was_retrieved
Logging the job information that was retrieved
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from app.extensions import redis_client
|
||||
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
|
||||
from app.utils.csv import get_user_preferred_timezone
|
||||
@@ -27,9 +29,7 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
|
||||
def get_job(self, service_id, job_id):
|
||||
params = {}
|
||||
job = self.get(
|
||||
url="/service/{}/job/{}".format(service_id, job_id), params=params
|
||||
)
|
||||
job = self.get(url=f"/service/{service_id}/job/{job_id}", params=params)
|
||||
|
||||
return job
|
||||
|
||||
@@ -40,13 +40,16 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
if statuses is not None:
|
||||
params["statuses"] = ",".join(statuses)
|
||||
|
||||
return self.get(url="/service/{}/job".format(service_id), params=params)
|
||||
job = self.get(url=f"/service/{service_id}/job", params=params)
|
||||
from pprint import pformat
|
||||
current_app.logger.info(pformat(job))
|
||||
return job
|
||||
|
||||
def get_uploads(self, service_id, limit_days=None, page=1):
|
||||
params = {"page": page}
|
||||
if limit_days is not None:
|
||||
params["limit_days"] = limit_days
|
||||
return self.get(url="/service/{}/upload".format(service_id), params=params)
|
||||
return self.get(url=f"/service/{service_id}/upload", params=params)
|
||||
|
||||
def has_sent_previously(
|
||||
self, service_id, template_id, template_version, original_file_name
|
||||
|
||||
@@ -1362,7 +1362,7 @@ def test_menu_all_services_for_platform_admin_user(
|
||||
page = str(page)
|
||||
assert url_for("main.choose_template", service_id=service_one["id"]) in page
|
||||
assert url_for("main.service_settings", service_id=service_one["id"]) in page
|
||||
assert url_for('main.api_keys', service_id=service_one['id']) not in page
|
||||
assert url_for("main.api_keys", service_id=service_one["id"]) not in page
|
||||
|
||||
|
||||
def test_route_for_service_permissions(
|
||||
|
||||
@@ -494,5 +494,5 @@ def test_should_show_message_note(
|
||||
|
||||
assert normalize_spaces(page.select_one("main p.notification-status").text) == (
|
||||
'Messages are sent immediately to the cell phone carrier, but will remain in "pending" status until we hear '
|
||||
'back from the carrier they have received it and attempted deliver. More information on delivery status.'
|
||||
"back from the carrier they have received it and attempted deliver. More information on delivery status."
|
||||
)
|
||||
|
||||
@@ -29,13 +29,13 @@ MOCK_JOBS = {
|
||||
"updated_at": "2024-01-25T23:02:25+00:00",
|
||||
}
|
||||
],
|
||||
'links': {
|
||||
'last': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=3',
|
||||
'next': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=3',
|
||||
'prev': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=1'
|
||||
"links": {
|
||||
"last": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=3",
|
||||
"next": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=3",
|
||||
"prev": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=1",
|
||||
},
|
||||
'page_size': 50,
|
||||
'total': 115
|
||||
"page_size": 50,
|
||||
"total": 115,
|
||||
}
|
||||
|
||||
|
||||
@@ -58,59 +58,62 @@ def test_all_activity(
|
||||
|
||||
assert "All activity" in response.text
|
||||
mock_get_page_of_jobs.assert_called_with(SERVICE_ONE_ID, page=current_page)
|
||||
page = BeautifulSoup(response.data, 'html.parser')
|
||||
table = page.find('table')
|
||||
page = BeautifulSoup(response.data, "html.parser")
|
||||
table = page.find("table")
|
||||
assert table is not None, "Table not found in the response"
|
||||
|
||||
headers = [th.get_text(strip=True) for th in table.find_all('th')]
|
||||
headers = [th.get_text(strip=True) for th in table.find_all("th")]
|
||||
expected_headers = ["Job ID#", "Template", "Time sent", "Sender", "Report"]
|
||||
|
||||
assert headers == expected_headers, f"Expected headers {expected_headers}, but got {headers}"
|
||||
assert (
|
||||
headers == expected_headers
|
||||
), f"Expected headers {expected_headers}, but got {headers}"
|
||||
|
||||
rows = table.find('tbody').find_all('tr', class_='table-row')
|
||||
rows = table.find("tbody").find_all("tr", class_="table-row")
|
||||
assert len(rows) == 1, "Expected one job row in the table"
|
||||
|
||||
job_row = rows[0]
|
||||
cells = job_row.find_all('td')
|
||||
cells = job_row.find_all("td")
|
||||
assert len(cells) == 5, "Expected five columns in the job row"
|
||||
|
||||
job_id_cell = cells[0].find('a').get_text(strip=True)
|
||||
job_id_cell = cells[0].find("a").get_text(strip=True)
|
||||
|
||||
assert job_id_cell == "55b242b5", f"Expected job ID '55b242b5', but got '{job_id_cell}'"
|
||||
assert (
|
||||
job_id_cell == "55b242b5"
|
||||
), f"Expected job ID '55b242b5', but got '{job_id_cell}'"
|
||||
template_cell = cells[1].get_text(strip=True)
|
||||
assert template_cell == "Mock Template Name", (
|
||||
f"Expected template 'Mock Template Name', but got '{template_cell}'"
|
||||
)
|
||||
assert (
|
||||
template_cell == "Mock Template Name"
|
||||
), f"Expected template 'Mock Template Name', but got '{template_cell}'"
|
||||
time_sent_cell = cells[2].get_text(strip=True)
|
||||
assert time_sent_cell == "01-25-2024 at 06:02 PM", (
|
||||
f"Expected time sent '01-25-2024 at 06:02 PM', but got '{time_sent_cell}'"
|
||||
)
|
||||
assert (
|
||||
time_sent_cell == "01-25-2024 at 06:02 PM"
|
||||
), f"Expected time sent '01-25-2024 at 06:02 PM', but got '{time_sent_cell}'"
|
||||
sender_cell = cells[3].get_text(strip=True)
|
||||
assert sender_cell == "mocked_user", f"Expected sender 'mocked_user', but got '{sender_cell}'"
|
||||
assert (
|
||||
sender_cell == "mocked_user"
|
||||
), f"Expected sender 'mocked_user', but got '{sender_cell}'"
|
||||
|
||||
report_cell = cells[4].find('span').get_text(strip=True)
|
||||
report_cell = cells[4].find("span").get_text(strip=True)
|
||||
assert report_cell == "N/A", f"Expected report 'N/A', but got '{report_cell}'"
|
||||
|
||||
mock_get_page_of_jobs.assert_called_with(SERVICE_ONE_ID, page=current_page)
|
||||
|
||||
|
||||
def test_all_activity_no_jobs(
|
||||
client_request,
|
||||
mocker
|
||||
):
|
||||
def test_all_activity_no_jobs(client_request, mocker):
|
||||
current_page = get_page_from_request()
|
||||
mock_get_page_of_jobs = mocker.patch(
|
||||
"app.job_api_client.get_page_of_jobs",
|
||||
return_value={
|
||||
"data": [],
|
||||
'links': {
|
||||
'last': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=1',
|
||||
'next': None,
|
||||
'prev': None
|
||||
"links": {
|
||||
"last": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=1",
|
||||
"next": None,
|
||||
"prev": None,
|
||||
},
|
||||
'page_size': 50,
|
||||
'total': 0
|
||||
}
|
||||
"page_size": 50,
|
||||
"total": 0,
|
||||
},
|
||||
)
|
||||
response = client_request.get_response(
|
||||
"main.all_jobs_activity",
|
||||
@@ -120,17 +123,17 @@ def test_all_activity_no_jobs(
|
||||
|
||||
assert response.status_code == 200, "Request failed"
|
||||
|
||||
page = BeautifulSoup(response.data, 'html.parser')
|
||||
page = BeautifulSoup(response.data, "html.parser")
|
||||
|
||||
no_jobs_message_td = page.find('td', class_='table-empty-message')
|
||||
no_jobs_message_td = page.find("td", class_="table-empty-message")
|
||||
assert no_jobs_message_td is not None, "No jobs message not found in the response"
|
||||
|
||||
expected_message = "No batched job messages found (messages are kept for 7 days)."
|
||||
actual_message = no_jobs_message_td.get_text(strip=True)
|
||||
|
||||
assert expected_message == actual_message, (
|
||||
f"Expected message '{expected_message}', but got '{actual_message}'"
|
||||
)
|
||||
assert (
|
||||
expected_message == actual_message
|
||||
), f"Expected message '{expected_message}', but got '{actual_message}'"
|
||||
mock_get_page_of_jobs.assert_called_with(SERVICE_ONE_ID, page=current_page)
|
||||
|
||||
|
||||
@@ -148,17 +151,18 @@ def test_all_activity_pagination(client_request, mocker):
|
||||
"processing_started": "2024-01-25T23:02:24+00:00",
|
||||
"template_name": "Mock Template Name",
|
||||
"original_file_name": "mocked_file.csv",
|
||||
"notification_count": 1
|
||||
} for i in range(1, 101)
|
||||
"notification_count": 1,
|
||||
}
|
||||
for i in range(1, 101)
|
||||
],
|
||||
'links': {
|
||||
'last': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=2',
|
||||
'next': '/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=2',
|
||||
'prev': None
|
||||
"links": {
|
||||
"last": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=2",
|
||||
"next": "/service/21b3ee3d-1cb0-4666-bfa0-9c5ac26d3fe3/job?page=2",
|
||||
"prev": None,
|
||||
},
|
||||
'page_size': 50,
|
||||
'total': 100
|
||||
}
|
||||
"page_size": 50,
|
||||
"total": 100,
|
||||
},
|
||||
)
|
||||
|
||||
response = client_request.get_response(
|
||||
@@ -168,12 +172,12 @@ def test_all_activity_pagination(client_request, mocker):
|
||||
)
|
||||
mock_get_page_of_jobs.assert_called_with(SERVICE_ONE_ID, page=current_page)
|
||||
|
||||
page = BeautifulSoup(response.data, 'html.parser')
|
||||
pagination_controls = page.find_all('li', class_='usa-pagination__item')
|
||||
page = BeautifulSoup(response.data, "html.parser")
|
||||
pagination_controls = page.find_all("li", class_="usa-pagination__item")
|
||||
assert pagination_controls, "Pagination controls not found in the response"
|
||||
|
||||
pagination_texts = [item.get_text(strip=True) for item in pagination_controls]
|
||||
expected_pagination_texts = ['1', '2', 'Next']
|
||||
assert pagination_texts == expected_pagination_texts, (
|
||||
f"Expected pagination controls {expected_pagination_texts}, but got {pagination_texts}"
|
||||
)
|
||||
expected_pagination_texts = ["1", "2", "Next"]
|
||||
assert (
|
||||
pagination_texts == expected_pagination_texts
|
||||
), f"Expected pagination controls {expected_pagination_texts}, but got {pagination_texts}"
|
||||
|
||||
@@ -36,8 +36,18 @@ def test_generate_previous_next_dict_adds_other_url_args(client_request):
|
||||
(500, 50, 1, {"current": 1, "pages": [1, 2, 3, 4, 5, 6, 7, 8, 9], "last": 10}),
|
||||
(500, 50, 5, {"current": 5, "pages": [1, 2, 3, 4, 5, 6, 7, 8, 9], "last": 10}),
|
||||
(500, 50, 6, {"current": 6, "pages": [2, 3, 4, 5, 6, 7, 8, 9, 10], "last": 10}),
|
||||
(500, 50, 10, {"current": 10, "pages": [2, 3, 4, 5, 6, 7, 8, 9, 10], "last": 10}),
|
||||
(950, 50, 15, {"current": 15, "pages": [11, 12, 13, 14, 15, 16, 17, 18, 19], "last": 19}),
|
||||
(
|
||||
500,
|
||||
50,
|
||||
10,
|
||||
{"current": 10, "pages": [2, 3, 4, 5, 6, 7, 8, 9, 10], "last": 10},
|
||||
),
|
||||
(
|
||||
950,
|
||||
50,
|
||||
15,
|
||||
{"current": 15, "pages": [11, 12, 13, 14, 15, 16, 17, 18, 19], "last": 19},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_generate_pagination_pages(total_items, page_size, current_page, expected):
|
||||
|
||||
Reference in New Issue
Block a user