mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 02:19:23 +02:00
Add unit test
This commit is contained in:
parent
e30650abee
commit
af20a9b52a
2 changed files with 23 additions and 1 deletions
|
@ -9,6 +9,7 @@ from django.db import models
|
||||||
from django_fsm import FSMField, transition # type: ignore
|
from django_fsm import FSMField, transition # type: ignore
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
|
from registrar.models.federal_agency import FederalAgency
|
||||||
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
||||||
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
||||||
|
|
||||||
|
@ -752,7 +753,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
notification."""
|
notification."""
|
||||||
|
|
||||||
if self.federal_agency is None:
|
if self.federal_agency is None:
|
||||||
self.federal_agency = "Non-Federal Agency"
|
self.federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
# create the domain
|
# create the domain
|
||||||
|
|
|
@ -12,6 +12,7 @@ from registrar.models import (
|
||||||
DraftDomain,
|
DraftDomain,
|
||||||
DomainInvitation,
|
DomainInvitation,
|
||||||
UserDomainRole,
|
UserDomainRole,
|
||||||
|
FederalAgency,
|
||||||
)
|
)
|
||||||
|
|
||||||
import boto3_mocking
|
import boto3_mocking
|
||||||
|
@ -75,6 +76,26 @@ class TestDomainRequest(TestCase):
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
return self.assertRaises(Exception, None, exception_type)
|
return self.assertRaises(Exception, None, exception_type)
|
||||||
|
|
||||||
|
def test_federal_agency_set_to_non_federal_on_approve(self):
|
||||||
|
"""Ensures that when the federal_agency field is 'none' when .approve() is called,
|
||||||
|
the field is set to the 'Non-Federal Agency' record"""
|
||||||
|
domain_request = completed_domain_request(
|
||||||
|
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
||||||
|
name="city2.gov",
|
||||||
|
federal_agency=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure that the federal agency is None
|
||||||
|
self.assertEqual(domain_request.federal_agency, None)
|
||||||
|
|
||||||
|
# Approve the request
|
||||||
|
domain_request.approve()
|
||||||
|
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED)
|
||||||
|
|
||||||
|
# After approval, it should be "Non-Federal agency"
|
||||||
|
expected_federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first()
|
||||||
|
self.assertEqual(domain_request.federal_agency, expected_federal_agency)
|
||||||
|
|
||||||
def test_empty_create_fails(self):
|
def test_empty_create_fails(self):
|
||||||
"""Can't create a completely empty domain request.
|
"""Can't create a completely empty domain request.
|
||||||
NOTE: something about theexception this test raises messes up with the
|
NOTE: something about theexception this test raises messes up with the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue