updated tests

This commit is contained in:
asaki222 2024-10-24 17:18:53 -04:00
parent a9aa8b16ef
commit 5a896ac369
No known key found for this signature in database
GPG key ID: 2C4F802060E06EA4
3 changed files with 28 additions and 4 deletions

View file

@ -1333,18 +1333,16 @@ class DomainRequest(TimeStampedModel):
return False
return True
"""the following converted_ property methods get their respective field names from portfolio, if the domain request has a portfolio. if it does not, it will get the info from the model itself."""
@property
def converted_organization_name(self):
""" "returns the organization field if the domain request is in a portfolio
otherwise it returns the organization name from the domain request object itself"""
if self.portfolio:
return self.portfolio.organization_name
return self.organization_name
@property
def converted_generic_org_type(self):
""" "returns the organization type if the domain request is in a portfolio
otherwise it returns the organization type from the domain request object itself"""
if self.portfolio:
return self.portfolio.organization_type
return self.generic_org_type

View file

@ -576,6 +576,8 @@ class TestDomainRequestAdmin(MockEppLib):
response = self.client.get("/admin/registrar/domainrequest/?generic_org_type__exact=federal")
# There are 2 template references to Federal (4) and two in the results data
# of the request
self.assertContains(response, "Federal", count=48)
self.assertContains(response, "Converted federal", count=4)
# This may be a bit more robust
self.assertContains(response, '<td class="field-converted_generic_org_type">federal</td>', count=1)
# Now let's make sure the long description does not exist

View file

@ -14,6 +14,7 @@ from registrar.models import (
DraftDomain,
FederalAgency,
AllowedEmail,
Portfolio,
)
import boto3_mocking
@ -95,6 +96,7 @@ class TestDomainRequest(TestCase):
DomainRequest.objects.all().delete()
DraftDomain.objects.all().delete()
Domain.objects.all().delete()
Portfolio.objects.all().delete()
User.objects.all().delete()
self.mock_client.EMAILS_SENT.clear()
@ -1045,3 +1047,25 @@ class TestDomainRequest(TestCase):
status=DomainRequest.DomainRequestStatus.STARTED, name="no-others.gov", has_other_contacts=False
)
self.assertEquals(domain_request.has_other_contacts(), False)
@less_console_noise_decorator
def test_converted_type(self):
"""test that new property fields works as expected to pull domain req info such as fed agency, generic org type, and others from portfolio"""
fed_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
portfolio = Portfolio.objects.create(
organization_name="Test Portfolio",
creator=self.dummy_user_2,
federal_agency=fed_agency,
organization_type=DomainRequest.OrganizationChoices.FEDERAL,
)
domain_request = completed_domain_request(name="domainre1.gov", portfolio=portfolio)
self.assertEqual(portfolio.organization_type, domain_request.converted_generic_org_type)
self.assertEqual(portfolio.federal_agency, domain_request.converted_federal_agency)
domain_request2 = completed_domain_request(
name="domainreq2.gov", federal_agency=fed_agency, generic_org_type=DomainRequest.OrganizationChoices.TRIBAL
)
self.assertEqual(domain_request2.generic_org_type, domain_request2.converted_generic_org_type)
self.assertEqual(domain_request2.federal_agency, domain_request2.converted_federal_agency)