Add unit tests and update descriptions

This commit is contained in:
Rebecca Hsieh 2024-04-23 11:19:56 -07:00
parent 556aee54fe
commit a7f7e5501e
No known key found for this signature in database
3 changed files with 76 additions and 28 deletions

View file

@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
help = "Transfers Domain Request and Domain Information federal agency field from string to FederalAgency object" help = "Transfers Domain Request and Domain Information federal agency field from string to FederalAgency object"
# Deprecated federal agency names mapped to designated replacements # Deprecated federal agency names mapped to designated replacements {old_value, new value}
rename_deprecated_federal_agency = { rename_deprecated_federal_agency = {
"Appraisal Subcommittee": "Appraisal Subcommittee of the Federal Financial Institutions Examination Council", "Appraisal Subcommittee": "Appraisal Subcommittee of the Federal Financial Institutions Examination Council",
"Barry Goldwater Scholarship and Excellence in Education Program": "Barry Goldwater Scholarship and Excellence in Education Foundation", "Barry Goldwater Scholarship and Excellence in Education Program": "Barry Goldwater Scholarship and Excellence in Education Foundation",

View file

@ -790,6 +790,7 @@ def create_ready_domain():
return domain return domain
# TODO in 1793: Remove the federal agency/updated federal agency fields
def completed_domain_request( def completed_domain_request(
has_other_contacts=True, has_other_contacts=True,
has_current_website=True, has_current_website=True,
@ -842,8 +843,7 @@ def completed_domain_request(
last_name="Bob", last_name="Bob",
is_staff=True, is_staff=True,
) )
if not updated_federal_agency:
updated_federal_agency, _ = FederalAgency.objects.get_or_create(agency="Stitches Is The Best")
domain_request_kwargs = dict( domain_request_kwargs = dict(
generic_org_type=generic_org_type, generic_org_type=generic_org_type,
is_election_board=is_election_board, is_election_board=is_election_board,
@ -871,10 +871,6 @@ def completed_domain_request(
if organization_type: if organization_type:
domain_request_kwargs["organization_type"] = organization_type domain_request_kwargs["organization_type"] = organization_type
# if federal_agency:
# domain_request_kwargs["federal_agency"] = federal_agency
# if updated_federal_agency:
# domain_request_kwargs["updated_federal_agency"] = updated_federal_agency
domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs) domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs)
if has_other_contacts: if has_other_contacts:

View file

@ -746,7 +746,8 @@ class TestDiscloseEmails(MockEppLib):
) )
class TestRenamingFederalAgency(MockEppLib): # TODO in #1793: Remove this whole test class
class TestRenamingFederalAgency(TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@ -758,17 +759,35 @@ class TestRenamingFederalAgency(MockEppLib):
status=DomainRequest.DomainRequestStatus.IN_REVIEW, status=DomainRequest.DomainRequestStatus.IN_REVIEW,
federal_agency="U.S. Peace Corps", federal_agency="U.S. Peace Corps",
) )
self.outdated_federal_agency = FederalAgency.objects.get_or_create(agency="U.S. Peace Corps") self.domain_request_2 = completed_domain_request(
self.corrected_federal_agency = FederalAgency.objects.get_or_create(agency="Peace Corps") name="fadoesntexist.gov",
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
is_election_board=True,
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
federal_agency="MEOWARDRULES",
)
self.domain_request_3 = completed_domain_request(
name="nullfederalagency.gov",
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
is_election_board=True,
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
federal_agency=None,
)
# Approve all three requests # Approve all three requests
self.domain_request_1.approve() self.domain_request_1.approve()
self.domain_request_2.approve()
self.domain_request_3.approve()
# Get the domains # Get the domains
self.domain_1 = Domain.objects.get(name="stitches.gov") self.domain_1 = Domain.objects.get(name="stitches.gov")
self.domain_2 = Domain.objects.get(name="fadoesntexist.gov")
self.domain_3 = Domain.objects.get(name="nullfederalagency.gov")
# Get the domain infos # Get the domain infos
self.domain_info_1 = DomainInformation.objects.get(domain=self.domain_1) self.domain_info_1 = DomainInformation.objects.get(domain=self.domain_1)
self.domain_info_2 = DomainInformation.objects.get(domain=self.domain_2)
self.domain_info_3 = DomainInformation.objects.get(domain=self.domain_3)
def tearDown(self): def tearDown(self):
super().tearDown() super().tearDown()
@ -783,32 +802,65 @@ class TestRenamingFederalAgency(MockEppLib):
The 'call_command' function from Django's management framework is then used to The 'call_command' function from Django's management framework is then used to
execute the populate_domain_updated_federal_agency command. execute the populate_domain_updated_federal_agency command.
""" """
# with less_console_noise(): with less_console_noise():
print("!! We are in run_populate_domain_updated_federal_agency") with patch(
with patch( "registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa return_value=True,
return_value=True, ):
): call_command("populate_domain_updated_federal_agency")
call_command("populate_domain_updated_federal_agency")
def test_domain_information_renaming_federal_agency_success(self): def test_domain_information_renaming_federal_agency_success(self):
""" """
1. Domain Information Update an outdated Federal Agency Domain Information updates successfully for an "outdated" Federal Agency
2. Domain Information should error out on null Update a Federal Agency that doesn't exist (should error out)
2a. Domain Request should just skip? (maybe)
3. Domain Request Updating a Null Federal Agency make sure it's updated to Non-Federal Agency
TODO: Have a todo for the next ticket pt 3 to remove the tests here RIP
""" """
# Test case #1
self.run_populate_domain_updated_federal_agency() self.run_populate_domain_updated_federal_agency()
print("!! self.domain_info_1 is", self.domain_info_1)
print("!! self.domain_info_1 dictionary is", self.domain_info_1.__dict__) self.domain_info_1.refresh_from_db()
previous_federal_agency_name = self.domain_info_1.federal_agency previous_federal_agency_name = self.domain_info_1.federal_agency
updated_federal_agency_name = self.domain_info_1.updated_federal_agency updated_federal_agency_name = self.domain_info_1.updated_federal_agency.agency
print("!! previous_federal_agency_name is ", previous_federal_agency_name)
print("!! updated_federal_agency_name is ", updated_federal_agency_name)
self.assertEqual(previous_federal_agency_name, "U.S. Peace Corps") self.assertEqual(previous_federal_agency_name, "U.S. Peace Corps")
self.assertEqual(updated_federal_agency_name, "Peace Corps") self.assertEqual(updated_federal_agency_name, "Peace Corps")
def test_domain_information_does_not_exist(self):
"""
Update a Federal Agency that doesn't exist
(should return None bc the Federal Agency didn't exist before)
"""
self.run_populate_domain_updated_federal_agency()
self.domain_info_2.refresh_from_db()
self.assertEqual(self.domain_info_2.updated_federal_agency, None)
def test_domain_request_is_skipped(self):
"""
Update a Domain Request that doesn't exist
(should return None bc the Federal Agency didn't exist before)
"""
# Test case #2
self.run_populate_domain_updated_federal_agency()
self.domain_request_2.refresh_from_db()
self.assertEqual(self.domain_request_2.updated_federal_agency, None)
def test_domain_information_updating_null_federal_agency_to_non_federal_agency(self):
"""
Updating a Domain Information that was previously None
to Non-Federal Agency
"""
self.run_populate_domain_updated_federal_agency()
self.domain_info_3.refresh_from_db()
previous_federal_agency_name = self.domain_info_3.federal_agency
updated_federal_agency_name = self.domain_info_3.updated_federal_agency.agency
self.assertEqual(previous_federal_agency_name, None)
self.assertEqual(updated_federal_agency_name, "Non-Federal Agency")