Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-06-12 | MAIN --> PROD | DEV (f2aa937) --> STAGING #3979

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
build_cell_error_tuple,
appears_empty,
)
from django.conf import settings

logger = logging.getLogger(__name__)

Expand All @@ -21,12 +22,14 @@
# digits are a year >= 1900.
# TESTED BY
# has_bad_references.xlsx
def finding_reference_pattern(ir):
def finding_reference_pattern(ir, is_gsa_migration=False):
references = get_range_by_name(ir, "reference_number")
errors = []
for index, reference in enumerate(references["values"]):
if not appears_empty(reference) and (
not re.match(FINDING_REFERENCE_REGEX, str(reference))
if (
not appears_empty(reference)
and (reference == settings.GSA_MIGRATION and not is_gsa_migration)
and (not re.match(FINDING_REFERENCE_REGEX, str(reference)))
):
errors.append(
build_cell_error_tuple(
Expand Down
2 changes: 2 additions & 0 deletions backend/audit/intakelib/checks/check_gsa_migration_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def check_for_gsa_migration_keyword(ir):
"material_weakness",
"significant_deficiency",
"repeat_prior_reference",
"reference_number",
"is_guaranteed",
]

for range_name in range_names:
Expand Down
2 changes: 1 addition & 1 deletion backend/audit/intakelib/checks/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"federal_program_total_is_correct": federal_program_total_is_correct,
}

require_gsa_migration_flag = [findings_grid_validation]
require_gsa_migration_flag = [findings_grid_validation, finding_reference_pattern]


def run_all_checks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ def _get_agency_prefixes(dbkey, year):
audits = get_audits(dbkey, year)

for audit_detail in audits:
agencies.add(string_to_string(audit_detail.CFDA_PREFIX))
prefix = (
string_to_string(audit_detail.CFDA_PREFIX)
if audit_detail.CFDA_PREFIX
else string_to_string(audit_detail.CFDA).split(".")[0]
)
agencies.add(prefix)

return agencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,21 @@ def xform_replace_empty_auditee_contact_name(general_information):
return general_information


def xform_replace_empty_auditee_contact_title(general_information):
"""Replaces empty auditee contact title with GSA Migration keyword"""
# Transformation recorded.
if not general_information.get("auditee_contact_title"):
general_information["auditee_contact_title"] = settings.GSA_MIGRATION
track_transformations(
"AUDITEETITLE",
"",
"auditee_contact_title",
general_information["auditee_contact_title"],
"xform_replace_empty_auditee_contact_title",
)
return general_information


def xform_replace_empty_or_invalid_auditee_uei_with_gsa_migration(audit_header):
"""Replaces empty or invalid auditee UEI with GSA Migration keyword"""
# Transformation recorded.
Expand Down Expand Up @@ -563,6 +578,7 @@ def general_information(audit_header):
xform_replace_empty_or_invalid_auditee_ein_with_gsa_migration,
xform_replace_empty_zips,
xform_replace_empty_auditee_contact_name,
xform_replace_empty_auditee_contact_title,
]

for transform in transformations:
Expand Down
61 changes: 61 additions & 0 deletions backend/census_historical_migration/test_federal_awards_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
xform_missing_major_program,
is_valid_extension,
xform_cluster_names,
xform_replace_missing_prefix,
xform_replace_required_values_with_gsa_migration_when_empty,
xform_sanitize_additional_award_identification,
)

Expand Down Expand Up @@ -851,3 +853,62 @@ def test_no_invalid_federal_program_total(self):
InvalidRecord.fields["validations_to_skip"],
)
self.assertNotIn


class TestXformMissingPrefix(SimpleTestCase):
class MockAudit:

def __init__(self, CFDA_PREFIX, CFDA):
self.CFDA_PREFIX = CFDA_PREFIX
self.CFDA = CFDA

def test_for_no_missing_prefix(self):
"""Test for no missing prefix"""
audits = [self.MockAudit("01", "01.123"), self.MockAudit("02", "02.456")]

xform_replace_missing_prefix(audits)

self.assertEqual(audits[0].CFDA_PREFIX, "01")
self.assertEqual(audits[1].CFDA_PREFIX, "02")

def test_for_missing_prefix(self):
"""Test for missing prefix"""
audits = [self.MockAudit("", "01.123"), self.MockAudit("02", "02.456")]

xform_replace_missing_prefix(audits)

self.assertEqual(audits[0].CFDA_PREFIX, "01")
self.assertEqual(audits[1].CFDA_PREFIX, "02")


class TestXformReplaceMissingFields(SimpleTestCase):

class MockAudit:

def __init__(
self,
LOANS,
DIRECT,
):
self.LOANS = LOANS
self.DIRECT = DIRECT

def test_replace_empty_fields(self):
audits = [
self.MockAudit(
LOANS="",
DIRECT="",
),
self.MockAudit(
LOANS="Present",
DIRECT="Present",
),
]

xform_replace_required_values_with_gsa_migration_when_empty(audits)

self.assertEqual(audits[0].LOANS, settings.GSA_MIGRATION)
self.assertEqual(audits[0].DIRECT, settings.GSA_MIGRATION)

self.assertEqual(audits[1].LOANS, "Present")
self.assertEqual(audits[1].DIRECT, "Present")
8 changes: 8 additions & 0 deletions backend/census_historical_migration/test_findings_xforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,15 @@ def __init__(
SIGNIFICANTDEFICIENCY,
OTHERFINDINGS,
QCOSTS,
FINDINGREFNUMS,
):
self.MODIFIEDOPINION = MODIFIEDOPINION
self.OTHERNONCOMPLIANCE = OTHERNONCOMPLIANCE
self.MATERIALWEAKNESS = MATERIALWEAKNESS
self.SIGNIFICANTDEFICIENCY = SIGNIFICANTDEFICIENCY
self.OTHERFINDINGS = OTHERFINDINGS
self.QCOSTS = QCOSTS
self.FINDINGREFNUMS = FINDINGREFNUMS

def test_replace_empty_fields(self):
findings = [
Expand All @@ -283,6 +285,7 @@ def test_replace_empty_fields(self):
SIGNIFICANTDEFICIENCY="",
OTHERFINDINGS="Present",
QCOSTS="",
FINDINGREFNUMS="",
),
self.Finding(
MODIFIEDOPINION="Present",
Expand All @@ -291,6 +294,7 @@ def test_replace_empty_fields(self):
SIGNIFICANTDEFICIENCY="",
OTHERFINDINGS="Present",
QCOSTS="",
FINDINGREFNUMS="Present",
),
self.Finding(
MODIFIEDOPINION="",
Expand All @@ -299,6 +303,7 @@ def test_replace_empty_fields(self):
SIGNIFICANTDEFICIENCY="",
OTHERFINDINGS="",
QCOSTS="Present",
FINDINGREFNUMS="",
),
]

Expand All @@ -310,20 +315,23 @@ def test_replace_empty_fields(self):
self.assertEqual(findings[0].SIGNIFICANTDEFICIENCY, settings.GSA_MIGRATION)
self.assertEqual(findings[0].OTHERFINDINGS, "Present")
self.assertEqual(findings[0].QCOSTS, settings.GSA_MIGRATION)
self.assertEqual(findings[0].FINDINGREFNUMS, settings.GSA_MIGRATION)

self.assertEqual(findings[1].MODIFIEDOPINION, "Present")
self.assertEqual(findings[1].OTHERNONCOMPLIANCE, "Present")
self.assertEqual(findings[1].MATERIALWEAKNESS, settings.GSA_MIGRATION)
self.assertEqual(findings[1].SIGNIFICANTDEFICIENCY, settings.GSA_MIGRATION)
self.assertEqual(findings[1].OTHERFINDINGS, "Present")
self.assertEqual(findings[1].QCOSTS, settings.GSA_MIGRATION)
self.assertEqual(findings[1].FINDINGREFNUMS, "Present")

self.assertEqual(findings[2].MODIFIEDOPINION, settings.GSA_MIGRATION)
self.assertEqual(findings[2].OTHERNONCOMPLIANCE, "Present")
self.assertEqual(findings[2].MATERIALWEAKNESS, "Present")
self.assertEqual(findings[2].SIGNIFICANTDEFICIENCY, settings.GSA_MIGRATION)
self.assertEqual(findings[2].OTHERFINDINGS, settings.GSA_MIGRATION)
self.assertEqual(findings[2].QCOSTS, "Present")
self.assertEqual(findings[2].FINDINGREFNUMS, settings.GSA_MIGRATION)


class TestXformMissingRepeatPriorReference(SimpleTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
xform_country_v2,
xform_entity_type,
xform_replace_empty_auditee_contact_name,
xform_replace_empty_auditee_contact_title,
xform_replace_empty_auditor_email,
xform_replace_empty_auditee_email,
xform_replace_empty_or_invalid_auditee_uei_with_gsa_migration,
Expand Down Expand Up @@ -319,6 +320,32 @@ def test_missing_auditee_contact_name(self):
)


class TestXformReplaceEmptyAuditeeContactTitle(SimpleTestCase):
def test_empty_auditee_contact_title(self):
"""Test that an empty auditee_contact_title is replaced with 'GSA_MIGRATION'"""
input_data = {"auditee_contact_title": ""}
expected_output = {"auditee_contact_title": settings.GSA_MIGRATION}
self.assertEqual(
xform_replace_empty_auditee_contact_title(input_data), expected_output
)

def test_non_empty_auditee_contact_title(self):
"""Test that a non-empty auditee_contact_title remains unchanged"""
input_data = {"auditee_contact_title": "test"}
expected_output = {"auditee_contact_title": "test"}
self.assertEqual(
xform_replace_empty_auditee_contact_title(input_data), expected_output
)

def test_missing_auditee_contact_title(self):
"""Test that a missing auditee_contact_title key is added and set to 'GSA_MIGRATION'"""
input_data = {}
expected_output = {"auditee_contact_title": settings.GSA_MIGRATION}
self.assertEqual(
xform_replace_empty_auditee_contact_title(input_data), expected_output
)


class TestXformReplaceEmptyOrInvalidUEIs(SimpleTestCase):
class MockAuditHeader:
def __init__(self, UEI):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.conf import settings
from django.test import SimpleTestCase

from census_historical_migration.change_record import InspectionRecord

from .workbooklib.secondary_auditors import (
xform_address_state,
xform_address_zipcode,
xform_cpafirmname,
xform_pad_contact_phone_with_nine,
)


Expand Down Expand Up @@ -101,3 +104,41 @@ def test_blank_cpafirm(self):
xform_cpafirmname(secondary_auditors)
self.assertEqual(secondary_auditors[0].CPAFIRMNAME, settings.GSA_MIGRATION)
self.assertEqual(secondary_auditors[1].CPAFIRMNAME, cpas[1].CPAFIRMNAME)


class TestXformPadContactPhoneWithNine(SimpleTestCase):

class MockSecondaryAuditorHeader:

def __init__(
self,
CPAPHONE,
):
self.CPAPHONE = CPAPHONE

def setUp(self):
self.secondary_auditors = [
self.MockSecondaryAuditorHeader(CPAPHONE="12345"),
self.MockSecondaryAuditorHeader(CPAPHONE="999999999"),
self.MockSecondaryAuditorHeader(CPAPHONE="1234567890"),
self.MockSecondaryAuditorHeader(CPAPHONE="98765432"),
]

def test_pad_contact_phone(self):
xform_pad_contact_phone_with_nine(self.secondary_auditors)

self.assertEqual(self.secondary_auditors[0].CPAPHONE, "12345") # No change
self.assertEqual(
self.secondary_auditors[1].CPAPHONE, "9999999999"
) # Pad applied
self.assertEqual(self.secondary_auditors[2].CPAPHONE, "1234567890") # No change
self.assertEqual(self.secondary_auditors[3].CPAPHONE, "98765432") # No change

def test_change_records(self):
secondary_auditors = [self.MockSecondaryAuditorHeader(CPAPHONE="999999999")]
change_records_before = len(InspectionRecord.change["secondary_auditor"])

xform_pad_contact_phone_with_nine(secondary_auditors)

change_records_after = len(InspectionRecord.change["secondary_auditor"])
self.assertEqual(change_records_after, change_records_before + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def xform_add_placeholder_for_missing_references(findings, captexts):
missing_references = expected_references - found_references
if missing_references:
for ref in missing_references:
if not ref:
ref = settings.GSA_MIGRATION
captexts.append(
CapText(
SEQ_NUMBER="0",
Expand Down
Loading
Loading