mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 05:54:11 +02:00
Update test_management_scripts.py
This commit is contained in:
parent
71603236eb
commit
e2d0f808b9
1 changed files with 74 additions and 2 deletions
|
@ -32,7 +32,14 @@ import tablib
|
||||||
from unittest.mock import patch, call, MagicMock, mock_open
|
from unittest.mock import patch, call, MagicMock, mock_open
|
||||||
from epplibwrapper import commands, common
|
from epplibwrapper import commands, common
|
||||||
|
|
||||||
from .common import MockEppLib, less_console_noise, completed_domain_request, MockSESClient, MockDbForIndividualTests
|
from .common import (
|
||||||
|
MockDb,
|
||||||
|
MockEppLib,
|
||||||
|
less_console_noise,
|
||||||
|
completed_domain_request,
|
||||||
|
MockSESClient,
|
||||||
|
MockDbForIndividualTests,
|
||||||
|
)
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
|
|
||||||
|
@ -1822,7 +1829,7 @@ class TestCreateFederalPortfolio(TestCase):
|
||||||
self.run_create_federal_portfolio(agency_name="Non-existent Agency", parse_requests=True)
|
self.run_create_federal_portfolio(agency_name="Non-existent Agency", parse_requests=True)
|
||||||
|
|
||||||
def test_does_not_update_existing_portfolio(self):
|
def test_does_not_update_existing_portfolio(self):
|
||||||
"""Tests that an existing portfolio is not updated"""
|
"""Tests that an existing portfolio is not updated when"""
|
||||||
# Create an existing portfolio
|
# Create an existing portfolio
|
||||||
existing_portfolio = Portfolio.objects.create(
|
existing_portfolio = Portfolio.objects.create(
|
||||||
federal_agency=self.federal_agency,
|
federal_agency=self.federal_agency,
|
||||||
|
@ -1845,6 +1852,71 @@ class TestCreateFederalPortfolio(TestCase):
|
||||||
self.assertEqual(existing_portfolio.notes, "Old notes")
|
self.assertEqual(existing_portfolio.notes, "Old notes")
|
||||||
self.assertEqual(existing_portfolio.creator, self.user)
|
self.assertEqual(existing_portfolio.creator, self.user)
|
||||||
|
|
||||||
|
def test_skip_existing_portfolios(self):
|
||||||
|
"""Tests the skip_existing_portfolios to ensure that it doesn't add
|
||||||
|
suborgs, domain requests, and domain info."""
|
||||||
|
# Create an existing portfolio with a suborganization
|
||||||
|
existing_portfolio = Portfolio.objects.create(
|
||||||
|
federal_agency=self.federal_agency,
|
||||||
|
organization_name="Test Federal Agency",
|
||||||
|
organization_type=DomainRequest.OrganizationChoices.CITY,
|
||||||
|
creator=self.user,
|
||||||
|
notes="Old notes",
|
||||||
|
)
|
||||||
|
|
||||||
|
existing_suborg = Suborganization.objects.create(
|
||||||
|
portfolio=existing_portfolio, name="Existing Suborg", city="Old City", state_territory="CA"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a domain request that would normally be associated
|
||||||
|
domain_request = completed_domain_request(
|
||||||
|
name="wackytaco.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.federal_agency,
|
||||||
|
user=self.user,
|
||||||
|
organization_name="would_create_suborg",
|
||||||
|
)
|
||||||
|
domain_request.approve()
|
||||||
|
domain = Domain.objects.get(name="wackytaco.gov").domain_info
|
||||||
|
|
||||||
|
# Run the command with skip_existing_portfolios=True
|
||||||
|
self.run_create_federal_portfolio(
|
||||||
|
agency_name="Test Federal Agency", parse_requests=True, skip_existing_portfolios=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Refresh objects from database
|
||||||
|
existing_portfolio.refresh_from_db()
|
||||||
|
existing_suborg.refresh_from_db()
|
||||||
|
domain_request.refresh_from_db()
|
||||||
|
domain.refresh_from_db()
|
||||||
|
|
||||||
|
# Verify nothing was changed on the portfolio itself
|
||||||
|
# SANITY CHECK: if the portfolio updates, it will change to FEDERAL.
|
||||||
|
# if this case fails, it means we are overriding data (and not simply just other weirdness)
|
||||||
|
self.assertNotEqual(existing_portfolio.organization_type, DomainRequest.OrganizationChoices.FEDERAL)
|
||||||
|
|
||||||
|
# Notes and creator should be untouched
|
||||||
|
self.assertEqual(existing_portfolio.organization_type, DomainRequest.OrganizationChoices.CITY)
|
||||||
|
self.assertEqual(existing_portfolio.organization_name, self.federal_agency.agency)
|
||||||
|
self.assertEqual(existing_portfolio.notes, "Old notes")
|
||||||
|
self.assertEqual(existing_portfolio.creator, self.user)
|
||||||
|
|
||||||
|
# Verify suborganization wasn't modified
|
||||||
|
self.assertEqual(existing_suborg.city, "Old City")
|
||||||
|
self.assertEqual(existing_suborg.state_territory, "CA")
|
||||||
|
|
||||||
|
# Verify that the domain request wasn't modified
|
||||||
|
self.assertIsNone(domain_request.portfolio)
|
||||||
|
self.assertIsNone(domain_request.sub_organization)
|
||||||
|
|
||||||
|
# Verify that the domain wasn't modified
|
||||||
|
self.assertIsNone(domain.portfolio)
|
||||||
|
self.assertIsNone(domain.sub_organization)
|
||||||
|
|
||||||
|
# Verify that a new suborg wasn't created
|
||||||
|
self.assertFalse(Suborganization.objects.filter(name="would_create_suborg").exists())
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_post_process_suborganization_fields(self):
|
def test_post_process_suborganization_fields(self):
|
||||||
"""Test suborganization field updates from domain and request data.
|
"""Test suborganization field updates from domain and request data.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue