mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 11:16:07 +02:00
Merge branch 'main' of https://github.com/cisagov/manage.get.gov into rh/3129-domain-renewal-form
This commit is contained in:
commit
ef43851991
7 changed files with 247 additions and 17 deletions
|
@ -4,7 +4,7 @@
|
||||||
* accessible directly in getgov.min.js
|
* accessible directly in getgov.min.js
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export function initializeTooltips() {
|
export function uswdsInitializeTooltips() {
|
||||||
function checkTooltip() {
|
function checkTooltip() {
|
||||||
// Check that the tooltip library is loaded, and if not, wait and retry
|
// Check that the tooltip library is loaded, and if not, wait and retry
|
||||||
if (window.tooltip && typeof window.tooltip.init === 'function') {
|
if (window.tooltip && typeof window.tooltip.init === 'function') {
|
||||||
|
|
|
@ -375,6 +375,13 @@ export class BaseTable {
|
||||||
*/
|
*/
|
||||||
loadModals(page, total, unfiltered_total) {}
|
loadModals(page, total, unfiltered_total) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads tooltips + sets up event listeners
|
||||||
|
* "Activates" the tooltips after the DOM updates
|
||||||
|
* Utilizes "uswdsInitializeTooltips"
|
||||||
|
*/
|
||||||
|
initializeTooltips() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows us to customize the table display based on specific conditions and a user's permissions
|
* Allows us to customize the table display based on specific conditions and a user's permissions
|
||||||
* Dynamically manages the visibility set up of columns, adding/removing headers
|
* Dynamically manages the visibility set up of columns, adding/removing headers
|
||||||
|
@ -471,6 +478,7 @@ export class BaseTable {
|
||||||
this.initCheckboxListeners();
|
this.initCheckboxListeners();
|
||||||
|
|
||||||
this.loadModals(data.page, data.total, data.unfiltered_total);
|
this.loadModals(data.page, data.total, data.unfiltered_total);
|
||||||
|
this.initializeTooltips();
|
||||||
|
|
||||||
// Do not scroll on first page load
|
// Do not scroll on first page load
|
||||||
if (scroll)
|
if (scroll)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { BaseTable } from './table-base.js';
|
import { BaseTable } from './table-base.js';
|
||||||
|
import { uswdsInitializeTooltips } from './helpers-uswds.js';
|
||||||
|
|
||||||
export class DomainsTable extends BaseTable {
|
export class DomainsTable extends BaseTable {
|
||||||
|
|
||||||
|
@ -66,6 +67,9 @@ export class DomainsTable extends BaseTable {
|
||||||
`;
|
`;
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
}
|
}
|
||||||
|
initializeTooltips() {
|
||||||
|
uswdsInitializeTooltips();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initDomainsTable() {
|
export function initDomainsTable() {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import logging
|
||||||
from django.core.management import BaseCommand, CommandError
|
from django.core.management import BaseCommand, CommandError
|
||||||
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper
|
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper
|
||||||
from registrar.models import DomainInformation, DomainRequest, FederalAgency, Suborganization, Portfolio, User
|
from registrar.models import DomainInformation, DomainRequest, FederalAgency, Suborganization, Portfolio, User
|
||||||
|
from registrar.models.utility.generic_helper import normalize_string
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -21,10 +22,21 @@ class Command(BaseCommand):
|
||||||
self.failed_portfolios = set()
|
self.failed_portfolios = set()
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
"""Add three arguments:
|
"""Add command line arguments to create federal portfolios.
|
||||||
1. agency_name => the value of FederalAgency.agency
|
|
||||||
2. --parse_requests => if true, adds the given portfolio to each related DomainRequest
|
Required (mutually exclusive) arguments:
|
||||||
3. --parse_domains => if true, adds the given portfolio to each related DomainInformation
|
--agency_name: Name of a specific FederalAgency to create a portfolio for
|
||||||
|
--branch: Federal branch to process ("executive", "legislative", or "judicial").
|
||||||
|
Creates portfolios for all FederalAgencies in that branch.
|
||||||
|
|
||||||
|
Required (at least one):
|
||||||
|
--parse_requests: Add the created portfolio(s) to related DomainRequest records
|
||||||
|
--parse_domains: Add the created portfolio(s) to related DomainInformation records
|
||||||
|
Note: You can use both --parse_requests and --parse_domains together
|
||||||
|
|
||||||
|
Optional (mutually exclusive with parse options):
|
||||||
|
--both: Shorthand for using both --parse_requests and --parse_domains
|
||||||
|
Cannot be used with --parse_requests or --parse_domains
|
||||||
"""
|
"""
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
group = parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
|
@ -78,12 +90,14 @@ class Command(BaseCommand):
|
||||||
else:
|
else:
|
||||||
raise CommandError(f"Cannot find '{branch}' federal agencies in our database.")
|
raise CommandError(f"Cannot find '{branch}' federal agencies in our database.")
|
||||||
|
|
||||||
|
portfolios = []
|
||||||
for federal_agency in agencies:
|
for federal_agency in agencies:
|
||||||
message = f"Processing federal agency '{federal_agency.agency}'..."
|
message = f"Processing federal agency '{federal_agency.agency}'..."
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
||||||
try:
|
try:
|
||||||
# C901 'Command.handle' is too complex (12)
|
# C901 'Command.handle' is too complex (12)
|
||||||
self.handle_populate_portfolio(federal_agency, parse_domains, parse_requests, both)
|
portfolio = self.handle_populate_portfolio(federal_agency, parse_domains, parse_requests, both)
|
||||||
|
portfolios.append(portfolio)
|
||||||
except Exception as exec:
|
except Exception as exec:
|
||||||
self.failed_portfolios.add(federal_agency)
|
self.failed_portfolios.add(federal_agency)
|
||||||
logger.error(exec)
|
logger.error(exec)
|
||||||
|
@ -99,9 +113,65 @@ class Command(BaseCommand):
|
||||||
display_as_str=True,
|
display_as_str=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# POST PROCESSING STEP: Remove the federal agency if it matches the portfolio name.
|
||||||
|
# We only do this for started domain requests.
|
||||||
|
if parse_requests or both:
|
||||||
|
TerminalHelper.prompt_for_execution(
|
||||||
|
system_exit_on_terminate=True,
|
||||||
|
prompt_message="This action will update domain requests even if they aren't on a portfolio.",
|
||||||
|
prompt_title=(
|
||||||
|
"POST PROCESS STEP: Do you want to clear federal agency on (related) started domain requests?"
|
||||||
|
),
|
||||||
|
verify_message=None,
|
||||||
|
)
|
||||||
|
self.post_process_started_domain_requests(agencies, portfolios)
|
||||||
|
|
||||||
|
def post_process_started_domain_requests(self, agencies, portfolios):
|
||||||
|
"""
|
||||||
|
Removes duplicate organization data by clearing federal_agency when it matches the portfolio name.
|
||||||
|
Only processes domain requests in STARTED status.
|
||||||
|
"""
|
||||||
|
message = "Removing duplicate portfolio and federal_agency values from domain requests..."
|
||||||
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message)
|
||||||
|
|
||||||
|
# For each request, clear the federal agency under these conditions:
|
||||||
|
# 1. A portfolio *already exists* with the same name as the federal agency.
|
||||||
|
# 2. Said portfolio (or portfolios) are only the ones specified at the start of the script.
|
||||||
|
# 3. The domain request is in status "started".
|
||||||
|
# Note: Both names are normalized so excess spaces are stripped and the string is lowercased.
|
||||||
|
domain_requests_to_update = DomainRequest.objects.filter(
|
||||||
|
federal_agency__in=agencies,
|
||||||
|
federal_agency__agency__isnull=False,
|
||||||
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
organization_name__isnull=False,
|
||||||
|
)
|
||||||
|
portfolio_set = {normalize_string(portfolio.organization_name) for portfolio in portfolios if portfolio}
|
||||||
|
|
||||||
|
# Update the request, assuming the given agency name matches the portfolio name
|
||||||
|
updated_requests = []
|
||||||
|
for req in domain_requests_to_update:
|
||||||
|
agency_name = normalize_string(req.federal_agency.agency)
|
||||||
|
if agency_name in portfolio_set:
|
||||||
|
req.federal_agency = None
|
||||||
|
updated_requests.append(req)
|
||||||
|
|
||||||
|
# Execute the update and Log the results
|
||||||
|
if TerminalHelper.prompt_for_execution(
|
||||||
|
system_exit_on_terminate=False,
|
||||||
|
prompt_message=(
|
||||||
|
f"{len(domain_requests_to_update)} domain requests will be updated. "
|
||||||
|
f"These records will be changed: {[str(req) for req in updated_requests]}"
|
||||||
|
),
|
||||||
|
prompt_title="Do you wish to commit this update to the database?",
|
||||||
|
):
|
||||||
|
DomainRequest.objects.bulk_update(updated_requests, ["federal_agency"])
|
||||||
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, "Action completed successfully.")
|
||||||
|
|
||||||
def handle_populate_portfolio(self, federal_agency, parse_domains, parse_requests, both):
|
def handle_populate_portfolio(self, federal_agency, parse_domains, parse_requests, both):
|
||||||
"""Attempts to create a portfolio. If successful, this function will
|
"""Attempts to create a portfolio. If successful, this function will
|
||||||
also create new suborganizations"""
|
also create new suborganizations.
|
||||||
|
Returns the portfolio for the given federal_agency.
|
||||||
|
"""
|
||||||
portfolio, created = self.create_portfolio(federal_agency)
|
portfolio, created = self.create_portfolio(federal_agency)
|
||||||
if created:
|
if created:
|
||||||
self.create_suborganizations(portfolio, federal_agency)
|
self.create_suborganizations(portfolio, federal_agency)
|
||||||
|
@ -111,6 +181,8 @@ class Command(BaseCommand):
|
||||||
if parse_requests or both:
|
if parse_requests or both:
|
||||||
self.handle_portfolio_requests(portfolio, federal_agency)
|
self.handle_portfolio_requests(portfolio, federal_agency)
|
||||||
|
|
||||||
|
return portfolio
|
||||||
|
|
||||||
def create_portfolio(self, federal_agency):
|
def create_portfolio(self, federal_agency):
|
||||||
"""Creates a portfolio if it doesn't presently exist.
|
"""Creates a portfolio if it doesn't presently exist.
|
||||||
Returns portfolio, created."""
|
Returns portfolio, created."""
|
||||||
|
@ -172,7 +244,7 @@ class Command(BaseCommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check for existing suborgs on the current portfolio
|
# Check for existing suborgs on the current portfolio
|
||||||
existing_suborgs = Suborganization.objects.filter(name__in=org_names)
|
existing_suborgs = Suborganization.objects.filter(name__in=org_names, name__isnull=False)
|
||||||
if existing_suborgs.exists():
|
if existing_suborgs.exists():
|
||||||
message = f"Some suborganizations already exist for portfolio '{portfolio}'."
|
message = f"Some suborganizations already exist for portfolio '{portfolio}'."
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, message)
|
||||||
|
@ -180,9 +252,7 @@ class Command(BaseCommand):
|
||||||
# Create new suborgs, as long as they don't exist in the db already
|
# Create new suborgs, as long as they don't exist in the db already
|
||||||
new_suborgs = []
|
new_suborgs = []
|
||||||
for name in org_names - set(existing_suborgs.values_list("name", flat=True)):
|
for name in org_names - set(existing_suborgs.values_list("name", flat=True)):
|
||||||
# Stored in variables due to linter wanting type information here.
|
if normalize_string(name) == normalize_string(portfolio.organization_name):
|
||||||
portfolio_name: str = portfolio.organization_name if portfolio.organization_name is not None else ""
|
|
||||||
if name is not None and name.lower() == portfolio_name.lower():
|
|
||||||
# You can use this to populate location information, when this occurs.
|
# You can use this to populate location information, when this occurs.
|
||||||
# However, this isn't needed for now so we can skip it.
|
# However, this isn't needed for now so we can skip it.
|
||||||
message = (
|
message = (
|
||||||
|
@ -229,12 +299,30 @@ class Command(BaseCommand):
|
||||||
# Get all suborg information and store it in a dict to avoid doing a db call
|
# Get all suborg information and store it in a dict to avoid doing a db call
|
||||||
suborgs = Suborganization.objects.filter(portfolio=portfolio).in_bulk(field_name="name")
|
suborgs = Suborganization.objects.filter(portfolio=portfolio).in_bulk(field_name="name")
|
||||||
for domain_request in domain_requests:
|
for domain_request in domain_requests:
|
||||||
|
# Set the portfolio
|
||||||
domain_request.portfolio = portfolio
|
domain_request.portfolio = portfolio
|
||||||
if domain_request.organization_name in suborgs:
|
|
||||||
domain_request.sub_organization = suborgs.get(domain_request.organization_name)
|
# Set suborg info
|
||||||
|
domain_request.sub_organization = suborgs.get(domain_request.organization_name, None)
|
||||||
|
if domain_request.sub_organization is None:
|
||||||
|
domain_request.requested_suborganization = normalize_string(
|
||||||
|
domain_request.organization_name, lowercase=False
|
||||||
|
)
|
||||||
|
domain_request.suborganization_city = normalize_string(domain_request.city, lowercase=False)
|
||||||
|
domain_request.suborganization_state_territory = domain_request.state_territory
|
||||||
|
|
||||||
self.updated_portfolios.add(portfolio)
|
self.updated_portfolios.add(portfolio)
|
||||||
|
|
||||||
DomainRequest.objects.bulk_update(domain_requests, ["portfolio", "sub_organization"])
|
DomainRequest.objects.bulk_update(
|
||||||
|
domain_requests,
|
||||||
|
[
|
||||||
|
"portfolio",
|
||||||
|
"sub_organization",
|
||||||
|
"requested_suborganization",
|
||||||
|
"suborganization_city",
|
||||||
|
"suborganization_state_territory",
|
||||||
|
],
|
||||||
|
)
|
||||||
message = f"Added portfolio '{portfolio}' to {len(domain_requests)} domain requests."
|
message = f"Added portfolio '{portfolio}' to {len(domain_requests)} domain requests."
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message)
|
||||||
|
|
||||||
|
@ -242,6 +330,8 @@ class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
Associate portfolio with domains for a federal agency.
|
Associate portfolio with domains for a federal agency.
|
||||||
Updates all relevant domain information records.
|
Updates all relevant domain information records.
|
||||||
|
|
||||||
|
Returns a queryset of DomainInformation objects, or None if nothing changed.
|
||||||
"""
|
"""
|
||||||
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency, portfolio__isnull=True)
|
domain_infos = DomainInformation.objects.filter(federal_agency=federal_agency, portfolio__isnull=True)
|
||||||
if not domain_infos.exists():
|
if not domain_infos.exists():
|
||||||
|
@ -257,8 +347,7 @@ class Command(BaseCommand):
|
||||||
suborgs = Suborganization.objects.filter(portfolio=portfolio).in_bulk(field_name="name")
|
suborgs = Suborganization.objects.filter(portfolio=portfolio).in_bulk(field_name="name")
|
||||||
for domain_info in domain_infos:
|
for domain_info in domain_infos:
|
||||||
domain_info.portfolio = portfolio
|
domain_info.portfolio = portfolio
|
||||||
if domain_info.organization_name in suborgs:
|
domain_info.sub_organization = suborgs.get(domain_info.organization_name, None)
|
||||||
domain_info.sub_organization = suborgs.get(domain_info.organization_name)
|
|
||||||
|
|
||||||
DomainInformation.objects.bulk_update(domain_infos, ["portfolio", "sub_organization"])
|
DomainInformation.objects.bulk_update(domain_infos, ["portfolio", "sub_organization"])
|
||||||
message = f"Added portfolio '{portfolio}' to {len(domain_infos)} domains."
|
message = f"Added portfolio '{portfolio}' to {len(domain_infos)} domains."
|
||||||
|
|
|
@ -343,3 +343,13 @@ def value_of_attribute(obj, attribute_name: str):
|
||||||
if callable(value):
|
if callable(value):
|
||||||
value = value()
|
value = value()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_string(string_to_normalize, lowercase=True):
|
||||||
|
"""Normalizes a given string. Returns a string without extra spaces, in all lowercase."""
|
||||||
|
if not isinstance(string_to_normalize, str):
|
||||||
|
logger.error(f"normalize_string => {string_to_normalize} is not type str.")
|
||||||
|
return string_to_normalize
|
||||||
|
|
||||||
|
new_string = " ".join(string_to_normalize.split())
|
||||||
|
return new_string.lower() if lowercase else new_string
|
||||||
|
|
|
@ -1039,6 +1039,8 @@ def completed_domain_request( # noqa
|
||||||
federal_agency=None,
|
federal_agency=None,
|
||||||
federal_type=None,
|
federal_type=None,
|
||||||
action_needed_reason=None,
|
action_needed_reason=None,
|
||||||
|
city=None,
|
||||||
|
state_territory=None,
|
||||||
portfolio=None,
|
portfolio=None,
|
||||||
organization_name=None,
|
organization_name=None,
|
||||||
sub_organization=None,
|
sub_organization=None,
|
||||||
|
@ -1081,7 +1083,7 @@ def completed_domain_request( # noqa
|
||||||
organization_name=organization_name if organization_name else "Testorg",
|
organization_name=organization_name if organization_name else "Testorg",
|
||||||
address_line1="address 1",
|
address_line1="address 1",
|
||||||
address_line2="address 2",
|
address_line2="address 2",
|
||||||
state_territory="NY",
|
state_territory="NY" if not state_territory else state_territory,
|
||||||
zipcode="10002",
|
zipcode="10002",
|
||||||
senior_official=so,
|
senior_official=so,
|
||||||
requested_domain=domain,
|
requested_domain=domain,
|
||||||
|
@ -1090,6 +1092,10 @@ def completed_domain_request( # noqa
|
||||||
investigator=investigator,
|
investigator=investigator,
|
||||||
federal_agency=federal_agency,
|
federal_agency=federal_agency,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if city:
|
||||||
|
domain_request_kwargs["city"] = city
|
||||||
|
|
||||||
if has_about_your_organization:
|
if has_about_your_organization:
|
||||||
domain_request_kwargs["about_your_organization"] = "e-Government"
|
domain_request_kwargs["about_your_organization"] = "e-Government"
|
||||||
if has_anything_else:
|
if has_anything_else:
|
||||||
|
|
|
@ -1516,6 +1516,91 @@ class TestCreateFederalPortfolio(TestCase):
|
||||||
):
|
):
|
||||||
call_command("create_federal_portfolio", **kwargs)
|
call_command("create_federal_portfolio", **kwargs)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_post_process_started_domain_requests_existing_portfolio(self):
|
||||||
|
"""Ensures that federal agency is cleared when agency name matches portfolio name.
|
||||||
|
As the name implies, this implicitly tests the "post_process_started_domain_requests" function.
|
||||||
|
"""
|
||||||
|
federal_agency_2 = FederalAgency.objects.create(agency="Sugarcane", federal_type=BranchChoices.EXECUTIVE)
|
||||||
|
|
||||||
|
# Test records with portfolios and no org names
|
||||||
|
# Create a portfolio. This script skips over "started"
|
||||||
|
portfolio = Portfolio.objects.create(organization_name="Sugarcane", creator=self.user)
|
||||||
|
# Create a domain request with matching org name
|
||||||
|
matching_request = completed_domain_request(
|
||||||
|
name="matching.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=federal_agency_2,
|
||||||
|
user=self.user,
|
||||||
|
portfolio=portfolio,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a request not in started (no change should occur)
|
||||||
|
matching_request_in_wrong_status = completed_domain_request(
|
||||||
|
name="kinda-matching.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.federal_agency,
|
||||||
|
user=self.user,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.run_create_federal_portfolio(agency_name="Sugarcane", parse_requests=True)
|
||||||
|
self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True)
|
||||||
|
|
||||||
|
# Refresh from db
|
||||||
|
matching_request.refresh_from_db()
|
||||||
|
matching_request_in_wrong_status.refresh_from_db()
|
||||||
|
|
||||||
|
# Request with matching name should have federal_agency cleared
|
||||||
|
self.assertIsNone(matching_request.federal_agency)
|
||||||
|
self.assertIsNotNone(matching_request.portfolio)
|
||||||
|
self.assertEqual(matching_request.portfolio.organization_name, "Sugarcane")
|
||||||
|
|
||||||
|
# Request with matching name but wrong state should keep its federal agency
|
||||||
|
self.assertEqual(matching_request_in_wrong_status.federal_agency, self.federal_agency)
|
||||||
|
self.assertIsNotNone(matching_request_in_wrong_status.portfolio)
|
||||||
|
self.assertEqual(matching_request_in_wrong_status.portfolio.organization_name, "Test Federal Agency")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_post_process_started_domain_requests(self):
|
||||||
|
"""Tests that federal agency is cleared when agency name
|
||||||
|
matches an existing portfolio's name, even if the domain request isn't
|
||||||
|
directly on that portfolio."""
|
||||||
|
|
||||||
|
federal_agency_2 = FederalAgency.objects.create(agency="Sugarcane", federal_type=BranchChoices.EXECUTIVE)
|
||||||
|
|
||||||
|
# Create a request with matching federal_agency name but no direct portfolio association
|
||||||
|
matching_agency_request = completed_domain_request(
|
||||||
|
name="agency-match.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=federal_agency_2,
|
||||||
|
user=self.user,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a control request that shouldn't match
|
||||||
|
non_matching_request = completed_domain_request(
|
||||||
|
name="no-match.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.federal_agency,
|
||||||
|
user=self.user,
|
||||||
|
)
|
||||||
|
|
||||||
|
# We expect the matching agency to have its fed agency cleared.
|
||||||
|
self.run_create_federal_portfolio(agency_name="Sugarcane", parse_requests=True)
|
||||||
|
matching_agency_request.refresh_from_db()
|
||||||
|
non_matching_request.refresh_from_db()
|
||||||
|
|
||||||
|
# Request with matching agency name should have federal_agency cleared
|
||||||
|
self.assertIsNone(matching_agency_request.federal_agency)
|
||||||
|
|
||||||
|
# Non-matching request should keep its federal_agency
|
||||||
|
self.assertIsNotNone(non_matching_request.federal_agency)
|
||||||
|
self.assertEqual(non_matching_request.federal_agency, self.federal_agency)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_create_single_portfolio(self):
|
def test_create_single_portfolio(self):
|
||||||
"""Test portfolio creation with suborg and senior official."""
|
"""Test portfolio creation with suborg and senior official."""
|
||||||
self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True)
|
self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True)
|
||||||
|
@ -1588,6 +1673,34 @@ class TestCreateFederalPortfolio(TestCase):
|
||||||
self.assertTrue(all([creator == User.get_default_user() for creator in creators]))
|
self.assertTrue(all([creator == User.get_default_user() for creator in creators]))
|
||||||
self.assertTrue(all([note == "Auto-generated record" for note in notes]))
|
self.assertTrue(all([note == "Auto-generated record" for note in notes]))
|
||||||
|
|
||||||
|
def test_script_adds_requested_suborganization_information(self):
|
||||||
|
"""Tests that the script adds the requested suborg fields for domain requests"""
|
||||||
|
# Create a new domain request with some errant spacing
|
||||||
|
custom_suborg_request = completed_domain_request(
|
||||||
|
name="custom_org.gov",
|
||||||
|
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
||||||
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.executive_agency_2,
|
||||||
|
user=self.user,
|
||||||
|
organization_name=" requested org name ",
|
||||||
|
city="Austin ",
|
||||||
|
state_territory=DomainRequest.StateTerritoryChoices.TEXAS,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertIsNone(custom_suborg_request.requested_suborganization)
|
||||||
|
self.assertIsNone(custom_suborg_request.suborganization_city)
|
||||||
|
self.assertIsNone(custom_suborg_request.suborganization_state_territory)
|
||||||
|
|
||||||
|
# Run the script and test it
|
||||||
|
self.run_create_federal_portfolio(branch="executive", parse_requests=True)
|
||||||
|
custom_suborg_request.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(custom_suborg_request.requested_suborganization, "requested org name")
|
||||||
|
self.assertEqual(custom_suborg_request.suborganization_city, "Austin")
|
||||||
|
self.assertEqual(
|
||||||
|
custom_suborg_request.suborganization_state_territory, DomainRequest.StateTerritoryChoices.TEXAS
|
||||||
|
)
|
||||||
|
|
||||||
def test_create_multiple_portfolios_for_branch_executive(self):
|
def test_create_multiple_portfolios_for_branch_executive(self):
|
||||||
"""Tests creating all portfolios under a given branch"""
|
"""Tests creating all portfolios under a given branch"""
|
||||||
federal_choice = DomainRequest.OrganizationChoices.FEDERAL
|
federal_choice = DomainRequest.OrganizationChoices.FEDERAL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue