-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Remove report flag for removal (#4566)
* #4434 Added django admin action to delete reports flagged for removal for over 6 months * Added test cases * Captured removal flag event * Adding transaction
- Loading branch information
Showing
6 changed files
with
245 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
from audit.models.models import SingleAuditReportFile | ||
|
||
from dissemination.remove_workbook_artifacts import delete_files_in_bulk | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def remove_singleauditreport_pdf(sac): | ||
""" | ||
Remove the single audit report pdf associated with the given sac. | ||
""" | ||
try: | ||
files = SingleAuditReportFile.objects.filter(sac=sac) | ||
files = [f"singleauditreport/{file.filename}" for file in files] | ||
if files: | ||
# Delete the files from S3 in bulk | ||
delete_files_in_bulk(files, sac) | ||
|
||
except SingleAuditReportFile.DoesNotExist: | ||
logger.info( | ||
f"No single audit report file found to delete for report: {sac.report_id}" | ||
) | ||
except Exception as e: | ||
logger.error( | ||
f"Failed to delete files from S3 for report: {sac.report_id}. Error: {e}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/dissemination/test_remove_singleauditreport_pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.test import TestCase | ||
from unittest.mock import patch | ||
from audit.models.models import SingleAuditChecklist, SingleAuditReportFile | ||
from dissemination.remove_singleauditreport_pdf import remove_singleauditreport_pdf | ||
from model_bakery import baker | ||
|
||
|
||
class TestRemoveSingleAuditReportPDF(TestCase): | ||
|
||
@patch("dissemination.remove_singleauditreport_pdf.delete_files_in_bulk") | ||
def test_remove_singleauditreport_pdf_success(self, mock_delete_files_in_bulk): | ||
sac = baker.make(SingleAuditChecklist, report_id="1900-01-GSAFAC-0000000001") | ||
baker.make( | ||
SingleAuditReportFile, | ||
filename="singleauditreport/1900-01-GSAFAC-0000000001.pdf", | ||
sac=sac, | ||
) | ||
|
||
remove_singleauditreport_pdf(sac) | ||
|
||
# Assert that delete_files_in_bulk is called with correct arguments | ||
mock_delete_files_in_bulk.assert_called_once_with( | ||
["singleauditreport/1900-01-GSAFAC-0000000001.pdf"], sac | ||
) | ||
|
||
@patch("dissemination.remove_singleauditreport_pdf.delete_files_in_bulk") | ||
def test_remove_singleauditreport_pdf_no_files(self, mock_delete_files_in_bulk): | ||
sac = baker.make(SingleAuditChecklist, report_id="1900-01-GSAFAC-0000000002") | ||
|
||
remove_singleauditreport_pdf(sac) | ||
|
||
mock_delete_files_in_bulk.assert_not_called() |