Fix report download buttons showing as disabled (#2840)

* Fix for lazy loading while checking if file exists

* Fixed linting errors

* Fixed for static scan
This commit is contained in:
Alex Janousek
2025-08-19 10:06:50 -04:00
committed by GitHub
parent 808aeabbe1
commit 74c1648c8d
4 changed files with 100 additions and 19 deletions

View File

@@ -0,0 +1,41 @@
from unittest.mock import Mock, patch
from app.main.views.activity import get_report_info
def test_report_metadata_loading_fix(mocker):
"""Test that metadata is loaded correctly after check_s3_file_exists"""
mock_s3_obj = Mock()
# After check_s3_file_exists calls load(), content_length is populated
mock_s3_obj.content_length = 86528
with patch("app.s3_client.get_s3_object", return_value=mock_s3_obj):
with patch("app.s3_client.check_s3_file_exists", return_value=True):
s3_config = {
"bucket": "test-bucket",
"access_key_id": "test-key",
"secret_access_key": "test-secret", # pragma: allowlist secret
"region": "us-east-1",
}
result = get_report_info("service-123", "1-day-report", s3_config)
assert result == {"available": True, "size": "84.5 KB"}
def test_report_not_found(mocker):
"""Test when report doesn't exist"""
mock_s3_obj = Mock()
with patch("app.s3_client.get_s3_object", return_value=mock_s3_obj):
with patch("app.s3_client.check_s3_file_exists", return_value=False):
s3_config = {
"bucket": "test-bucket",
"access_key_id": "test-key",
"secret_access_key": "test-secret", # pragma: allowlist secret
"region": "us-east-1",
}
result = get_report_info("service-123", "1-day-report", s3_config)
assert result == {"available": False, "size": None}