-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3402 Restructured code and added test
- Loading branch information
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
backend/curation/historical_records/test_fix_census_sac_auditee_certification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from audit.models import SingleAuditChecklist | ||
from census_historical_migration.models import ELECAUDITHEADER | ||
from .fix_census_sac_auditee_certification import update_census_sac_auditee_name | ||
from model_bakery import baker | ||
|
||
|
||
class TestUpdateCensusSacAuditeeName(unittest.TestCase): | ||
|
||
@patch.object(SingleAuditChecklist, "save", MagicMock()) | ||
def test_update_census_sac_auditee_name_with_valid_audit_header(self): | ||
sac = baker.make( | ||
SingleAuditChecklist, | ||
auditee_certification={ | ||
"auditee_signature": { | ||
"auditee_name": "Old Name", | ||
"auditee_title": "Old Title", | ||
} | ||
}, | ||
) | ||
audit_header = baker.make( | ||
ELECAUDITHEADER, | ||
AUDITEECERTIFYNAME="Auditee Name", | ||
AUDITEECERTIFYTITLE="Auditee Title", | ||
) | ||
|
||
update_census_sac_auditee_name(sac, audit_header) | ||
|
||
self.assertEqual( | ||
sac.auditee_certification["auditee_signature"]["auditee_name"], | ||
"Auditee Name", | ||
) | ||
self.assertEqual( | ||
sac.auditee_certification["auditee_signature"]["auditee_title"], | ||
"Auditee Title", | ||
) | ||
|
||
@patch.object(SingleAuditChecklist, "save", MagicMock()) | ||
def test_update_census_sac_auditee_name_with_gsa_migration(self): | ||
# Arrange | ||
sac = baker.make( | ||
SingleAuditChecklist, | ||
auditee_certification={ | ||
"auditee_signature": { | ||
"auditee_name": "Old Name", | ||
"auditee_title": "Old Title", | ||
} | ||
}, | ||
) | ||
audit_header = baker.make( | ||
ELECAUDITHEADER, | ||
AUDITEECERTIFYNAME="", | ||
AUDITEECERTIFYTITLE="Auditee Title", | ||
) # Empty AUDITEECERTIFYNAME is replaced with GSA_MIGRATION | ||
|
||
update_census_sac_auditee_name(sac, audit_header) | ||
|
||
self.assertEqual( | ||
sac.auditee_certification["auditee_signature"]["auditee_name"], | ||
"GSA_MIGRATION", | ||
) | ||
self.assertEqual( | ||
sac.auditee_certification["auditee_signature"]["auditee_title"], | ||
"Auditee Title", | ||
) | ||
|
||
@patch.object(SingleAuditChecklist, "save", MagicMock()) | ||
def test_update_census_sac_auditee_name_preserves_existing_data_in_auditee_signature( | ||
self, | ||
): | ||
# Arrange | ||
sac = baker.make( | ||
SingleAuditChecklist, | ||
auditee_certification={ | ||
"auditee_signature": {"some_other_field": "existing_value"} | ||
}, | ||
) | ||
audit_header = baker.make( | ||
ELECAUDITHEADER, | ||
AUDITEECERTIFYNAME="New Name", | ||
AUDITEECERTIFYTITLE="New Title", | ||
) | ||
|
||
update_census_sac_auditee_name(sac, audit_header) | ||
|
||
auditee_signature = sac.auditee_certification["auditee_signature"] | ||
self.assertEqual(auditee_signature["auditee_name"], "New Name") | ||
self.assertEqual(auditee_signature["auditee_title"], "New Title") | ||
self.assertEqual(auditee_signature["some_other_field"], "existing_value") |