Skip to content

Commit

Permalink
3945 address historical report with invalid secondary auditor phone c…
Browse files Browse the repository at this point in the history
…ontact (#3947)

* #3945 Updated code to pad a nine digit phone contact

* Linting

* #3945 Added test case

* Update backend/census_historical_migration/workbooklib/secondary_auditors.py

Co-authored-by: Phil Dominguez <[email protected]>

---------

Co-authored-by: Phil Dominguez <[email protected]>
  • Loading branch information
sambodeme and phildominguez-gsa authored Jun 11, 2024
1 parent f438cee commit 24a05e0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
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 @@ -155,6 +155,30 @@ def xform_cpafirmname(secondary_auditors):
InspectionRecord.append_secondary_auditor_changes(change_records)


def xform_pad_contact_phone_with_nine(secondary_auditors):
"""Pad contact phone with 9s if less than 10 digits"""
change_records = []
is_pad_applied = False
for secondary_auditor in secondary_auditors:
contact_phone = string_to_string(secondary_auditor.CPAPHONE)
if contact_phone == "999999999":
contact_phone = "9999999999"
is_pad_applied = True
track_transformations(
"CPAPHONE",
secondary_auditor.CPAPHONE,
"contact_phone",
contact_phone,
["xform_contact_phone"],
change_records,
)
secondary_auditor.CPAPHONE = contact_phone

# See Transformation Method Change Recording comment at the top of this file
if change_records and is_pad_applied:
InspectionRecord.append_secondary_auditor_changes(change_records)


def generate_secondary_auditors(audit_header, outfile):
"""
Generates secondary auditor workbook for a given audit header.
Expand All @@ -174,6 +198,7 @@ def generate_secondary_auditors(audit_header, outfile):
xform_address_state(secondary_auditors)
xform_address_zipcode(secondary_auditors)
xform_cpafirmname(secondary_auditors)
xform_pad_contact_phone_with_nine(secondary_auditors)
map_simple_columns(wb, mappings, secondary_auditors)
wb.save(outfile)

Expand Down

0 comments on commit 24a05e0

Please sign in to comment.