From 24a05e03662670d514eeba8923ec8d0e1480ea02 Mon Sep 17 00:00:00 2001 From: "Hassan D. M. Sambo" Date: Tue, 11 Jun 2024 15:01:51 -0400 Subject: [PATCH] 3945 address historical report with invalid secondary auditor phone contact (#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 <142051477+phildominguez-gsa@users.noreply.github.com> --------- Co-authored-by: Phil Dominguez <142051477+phildominguez-gsa@users.noreply.github.com> --- .../test_secondary_auditors_xforms.py | 41 +++++++++++++++++++ .../workbooklib/secondary_auditors.py | 25 +++++++++++ 2 files changed, 66 insertions(+) diff --git a/backend/census_historical_migration/test_secondary_auditors_xforms.py b/backend/census_historical_migration/test_secondary_auditors_xforms.py index 6994ca81fa..dbaeafa632 100644 --- a/backend/census_historical_migration/test_secondary_auditors_xforms.py +++ b/backend/census_historical_migration/test_secondary_auditors_xforms.py @@ -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, ) @@ -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) diff --git a/backend/census_historical_migration/workbooklib/secondary_auditors.py b/backend/census_historical_migration/workbooklib/secondary_auditors.py index c47ff12ca1..a6b10a81dc 100644 --- a/backend/census_historical_migration/workbooklib/secondary_auditors.py +++ b/backend/census_historical_migration/workbooklib/secondary_auditors.py @@ -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. @@ -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)