From be95d5a4776bc02190b65a58aa1bbb4f5ab36362 Mon Sep 17 00:00:00 2001 From: "Hassan D. M. Sambo" Date: Tue, 16 Jan 2024 15:34:10 -0500 Subject: [PATCH] #3202 Updated code to migrate cognizant and oversight data (#3204) * #3202 Updated code to migrate cognizant and oversight data * #3202 Fixed failing tests --- .../sac_general_lib/cognizant_oversight.py | 15 +++++++++++++++ .../sac_general_lib/sac_creator.py | 5 +++++ .../test_sac_creation.py | 2 ++ 3 files changed, 22 insertions(+) create mode 100644 backend/census_historical_migration/sac_general_lib/cognizant_oversight.py diff --git a/backend/census_historical_migration/sac_general_lib/cognizant_oversight.py b/backend/census_historical_migration/sac_general_lib/cognizant_oversight.py new file mode 100644 index 0000000000..48f3c60d63 --- /dev/null +++ b/backend/census_historical_migration/sac_general_lib/cognizant_oversight.py @@ -0,0 +1,15 @@ +from ..exception_utils import DataMigrationError +from ..transforms.xform_string_to_string import string_to_string + + +def cognizant_oversight(audit_header): + """Retrieve cognizant oversight information for a given audit header.""" + + cognizant = string_to_string(audit_header.COGAGENCY) + oversight = string_to_string(audit_header.OVERSIGHTAGENCY) + if cognizant and len(cognizant) > 2: + raise DataMigrationError( + f"Invalid cognizant agency: {cognizant}", "invalid_cognizant" + ) + + return cognizant, oversight diff --git a/backend/census_historical_migration/sac_general_lib/sac_creator.py b/backend/census_historical_migration/sac_general_lib/sac_creator.py index a2e5e9b51c..438a051e16 100644 --- a/backend/census_historical_migration/sac_general_lib/sac_creator.py +++ b/backend/census_historical_migration/sac_general_lib/sac_creator.py @@ -3,6 +3,8 @@ from django.apps import apps from django.conf import settings +from .cognizant_oversight import cognizant_oversight + from ..exception_utils import DataMigrationError from .general_information import ( general_information, @@ -80,6 +82,9 @@ def setup_sac(user, audit_header): sac.auditee_certification = auditee_certification(audit_header) sac.auditor_certification = auditor_certification(audit_header) + cognizant, oversight = cognizant_oversight(audit_header) + sac.cognizant_agency = cognizant + sac.oversight_agency = oversight sac.data_source = settings.CENSUS_DATA_SOURCE if general_info["user_provided_organization_type"] == "tribal": diff --git a/backend/census_historical_migration/test_sac_creation.py b/backend/census_historical_migration/test_sac_creation.py index ea9214b583..423c1c3e90 100644 --- a/backend/census_historical_migration/test_sac_creation.py +++ b/backend/census_historical_migration/test_sac_creation.py @@ -56,6 +56,8 @@ def __init__( self.TYPEREPORT_SP_FRAMEWORK = "UQAD" self.UEI = "ZQGGHJH74DW7" self.ZIPCODE = "10451" + self.COGAGENCY = "14" + self.OVERSIGHTAGENCY = "84" def _mock_audit_header(self, entity_type, suppression_code=None): """Returns a mock audit header with all necessary fields"""