Skip to content

Commit

Permalink
#4589 Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sambodeme committed Jan 10, 2025
1 parent 84e8f1b commit 72a8013
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
20 changes: 18 additions & 2 deletions backend/audit/intakelib/checks/check_finding_reference_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,25 @@ def finding_reference_year(ir, is_gsa_migration=False):
references = get_range_by_name(ir, "reference_number")
range_start = int(get_range_start_row(references))
errors = []
if is_gsa_migration:
return errors
sac = get_sac_from_context()

if is_gsa_migration or sac and sac.general_information is None:
# In real use cases, no report can be created if auditee_uei is missing, as it is a required field.
# The condition sac.general_information is None can occur only in test cases
# where general_information has been ignored purposefully (like in test_workbooks_should_pass.py).
return
elif sac is None:
raise ValidationError(
(
"(O_o)",
"",
"Workbook Validation Failed",
{
"text": "The workbook cannot be validated at the moment. Please contact the helpdesk for assistance.",
"link": "Intake checks: no link defined",
},
)
)
audit_date = sac.general_information["auditee_fiscal_period_end"]
audit_year = int(audit_date.split("-")[0])
for index, reference in enumerate(references["values"]):
Expand Down
39 changes: 36 additions & 3 deletions backend/audit/test_check_finding_reference_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def test_success(self):
"""
Test case where all finding reference years match the audit year.
"""
self.mock_sac.general_information = {"auditee_fiscal_period_end": "2022-12-31"}
self.mock_sac.general_information = {
"auditee_fiscal_period_end": "2022-12-31",
"auditee_uei": "UEI",
}
with set_sac_to_context(self.mock_sac):

errors = finding_reference_year(self.ir)
Expand All @@ -37,7 +40,10 @@ def test_mismatched_years(self):
"""
Test case where finding reference years do not match the audit year.
"""
self.mock_sac.general_information = {"auditee_fiscal_period_end": "2023-12-31"}
self.mock_sac.general_information = {
"auditee_fiscal_period_end": "2023-12-31",
"auditee_uei": "UEI",
}
with set_sac_to_context(self.mock_sac):
with self.assertRaises(ValidationError) as context:
finding_reference_year(self.ir)
Expand All @@ -54,4 +60,31 @@ def test_gsa_migration(self):
"""
errors = finding_reference_year(self.ir, is_gsa_migration=True)

self.assertEqual(errors, [])
self.assertEqual(errors, None)

def test_auditee_uei_missing(self):
"""
Test case where auditee_uei is None and the function returns without validation.
"""
self.mock_sac.general_information = {
"auditee_fiscal_period_end": "2022-12-31",
"auditee_uei": None,
}
with set_sac_to_context(self.mock_sac):
errors = finding_reference_year(self.ir)
self.assertEqual(errors, None)

def test_sac_is_none(self):
"""
Test case where sac is None and a ValidationError is raised.
"""
with set_sac_to_context(None):
with self.assertRaises(ValidationError) as context:
finding_reference_year(self.ir)

error = context.exception.args[0]
self.assertEqual(error[2], "Workbook Validation Failed")
self.assertEqual(
error[3]["text"],
"The workbook cannot be validated at the moment. Please contact the helpdesk for assistance.",
)
19 changes: 11 additions & 8 deletions backend/audit/test_workbooks_should_pass.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.test import SimpleTestCase
from django.test import TestCase
import os
from functools import reduce
import re


from audit.context import set_sac_to_context
from model_bakery import baker
from .models import SingleAuditChecklist
from audit.intakelib import (
extract_additional_eins,
extract_additional_ueis,
Expand Down Expand Up @@ -76,12 +77,14 @@ def process_workbook_set(workbook_set_path, is_gsa_migration=True):
raise Exception(msg)


class PassingWorkbooks(SimpleTestCase):
class PassingWorkbooks(TestCase):
def test_passing_workbooks(self):
workbook_sets = reduce(
os.path.join, ["audit", "fixtures", "workbooks", "should_pass"]
)
for dirpath, dirnames, _ in os.walk(workbook_sets):
for workbook_set in dirnames:
print("Walking ", workbook_set)
process_workbook_set(os.path.join(dirpath, workbook_set))
sac = baker.make(SingleAuditChecklist)
with set_sac_to_context(sac):
for dirpath, dirnames, _ in os.walk(workbook_sets):
for workbook_set in dirnames:
print("Walking ", workbook_set)
process_workbook_set(os.path.join(dirpath, workbook_set))

0 comments on commit 72a8013

Please sign in to comment.