Refactored reports to use pregenerated docs instead (#2831)

* Refactored reports to use pregenerated docs instead

* Fixed e2e test

* Fixed anothr bug

* Cleanup

* Fixed timezone conversion

* Updated ref files

* Updated reference files, refreshed ui/ux for report generation. Buttons toggle on and off based on if report exists

* Fixed linting errors, removed pytz

* Fixed test failure

* e2e test fix

* Speeding up unit tests

* Removed python time library that was causing performance issues with unit tests

* Updated poetry lock

* Unit test improvements

* Made change that ken reccomended
This commit is contained in:
Alex Janousek
2025-08-15 15:02:54 -04:00
committed by GitHub
parent 748c35d2df
commit 8d33f28b76
50 changed files with 632 additions and 204 deletions

View File

@@ -5,6 +5,8 @@ from boto3 import Session
from botocore.config import Config
from flask import current_app
from notifications_utils.s3 import S3ObjectNotFound
AWS_CLIENT_CONFIG = Config(
# This config is required to enable S3 to connect to FIPS-enabled
# endpoints. See https://aws.amazon.com/compliance/fips/ for more
@@ -48,6 +50,19 @@ def get_s3_object(
return obj
def check_s3_file_exists(obj):
try:
obj.load()
return True
except botocore.exceptions.ClientError as client_error:
if client_error.response["Error"]["Code"] in ["404", "NoSuchKey"]:
return False
current_app.logger.error(
f"Error checking S3 file {obj.bucket_name}/{obj.key}: {client_error}"
)
return False
def get_s3_metadata(obj):
try:
return obj.get()["Metadata"]
@@ -55,6 +70,8 @@ def get_s3_metadata(obj):
current_app.logger.error(
f"Unable to download s3 file {obj.bucket_name}/{obj.key}"
)
if client_error.response["Error"]["Code"] == "NoSuchKey":
raise S3ObjectNotFound(client_error.response, client_error.operation_name)
raise client_error
@@ -69,12 +86,13 @@ def set_s3_metadata(obj, **kwargs):
def get_s3_contents(obj):
contents = ""
try:
contents = obj.get()["Body"].read().decode("utf-8")
response = obj.get()
return response["Body"].read().decode("utf-8")
except botocore.exceptions.ClientError as client_error:
current_app.logger.error(
f"Unable to download s3 file {obj.bucket_name}/{obj.key}"
)
if client_error.response["Error"]["Code"] == "NoSuchKey":
raise S3ObjectNotFound(client_error.response, client_error.operation_name)
raise client_error
return contents

View File

@@ -4,6 +4,7 @@ import uuid
from flask import current_app
from app.s3_client import (
check_s3_file_exists,
get_s3_contents,
get_s3_metadata,
get_s3_object,
@@ -72,3 +73,7 @@ def set_metadata_on_csv_upload(service_id, upload_id, **kwargs):
def get_csv_metadata(service_id, upload_id):
return get_s3_metadata(get_csv_upload(service_id, upload_id))
def check_s3_report_exists(service_id, upload_id):
return check_s3_file_exists(get_csv_upload(service_id, upload_id))