fix tests and lint

This commit is contained in:
zandercymatics 2025-03-24 08:20:55 -06:00
parent 1ccaea5028
commit 3cefc4c24a
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 22 additions and 18 deletions

View file

@ -894,32 +894,32 @@ Example: `cf ssh getgov-za`
#### Step 5: Running the script #### Step 5: Running the script
To create a specific portfolio: To create a specific portfolio:
```./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --both``` ```./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --parse_domains --parse_requests --parse_managers```
Example (only requests): `./manage.py create_federal_portfolio "AMTRAK" --parse_requests` Example (only requests): `./manage.py create_federal_portfolio "AMTRAK" --parse_requests`
To create a portfolios for all federal agencies in a branch: To create a portfolios for all federal agencies in a branch:
```./manage.py create_federal_portfolio --branch "{executive|legislative|judicial}" --both``` ```./manage.py create_federal_portfolio --branch "{executive|legislative|judicial}" --parse_domains --parse_requests --parse_managers```
Example (only requests): `./manage.py create_federal_portfolio --branch "executive" --parse_requests` Example (only requests): `./manage.py create_federal_portfolio --branch "executive" --parse_requests`
### Running locally ### Running locally
#### Step 1: Running the script #### Step 1: Running the script
```docker-compose exec app ./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --both``` ```docker-compose exec app ./manage.py create_federal_portfolio --agency_name "{federal_agency_name}" --parse_domains```
##### Parameters ##### Parameters
| | Parameter | Description | | | Parameter | Description |
|:-:|:---------------------------- |:-------------------------------------------------------------------------------------------| |:-:|:---------------------------- |:-------------------------------------------------------------------------------------------|
| 1 | **agency_name** | Name of the FederalAgency record surrounded by quotes. For instance,"AMTRAK". | | 1 | **agency_name** | Name of the FederalAgency record surrounded by quotes. For instance,"AMTRAK". |
| 2 | **branch** | Creates a portfolio for each federal agency in a branch: executive, legislative, judicial | | 2 | **branch** | Creates a portfolio for each federal agency in a branch: executive, legislative, judicial |
| 3 | **both** | If True, runs parse_requests and parse_domains. | | 3 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. |
| 4 | **parse_requests** | If True, then the created portfolio is added to all related DomainRequests. | | 4 | **parse_domains** | If True, then the created portfolio is added to all related Domains. |
| 5 | **parse_domains** | If True, then the created portfolio is added to all related Domains. | | 5 | **parse_members** | If True, then the created portfolio will add all managers of the portfolio domains as members of the portfolio, including invited managers. |
| 6 | **add_managers** | If True, then the created portfolio will add all managers of the portfolio domains as members of the portfolio, including invited managers. | | 6 | **skip_existing_portfolios** | If True, then the script will only create suborganizations, modify DomainRequest, and modify DomainInformation records only when creating a new portfolio. Use this flag when you do not want to modify existing records. |
| 7 | **skip_existing_portfolios** | If True, then the script will only create suborganizations, modify DomainRequest, and modify DomainInformation records only when creating a new portfolio. Use this flag when you do not want to modify existing records. | | 7 | **Debug** | Increases log verbosity |
- Parameters #1-#2: Either `--agency_name` or `--branch` must be specified. Not both. - Parameters #1-#2: Either `--agency_name` or `--branch` must be specified. Not both.
- Parameters #2-#3, you cannot use `--both` while using these. You must specify either `--parse_requests` or `--parse_domains` seperately. While all of these parameters are optional in that you do not need to specify all of them, - Parameters #3-#5, while all of these parameters are optional in that you do not need to specify all of them,
you must specify at least one to run this script. you must specify at least one to run this script. You can also chain all of them together.
## Patch suborganizations ## Patch suborganizations

View file

@ -257,7 +257,7 @@ class Command(BaseCommand):
def print_final_run_summary(self, parse_domains, parse_requests, parse_managers, debug): def print_final_run_summary(self, parse_domains, parse_requests, parse_managers, debug):
self.portfolio_changes.print_script_run_summary( self.portfolio_changes.print_script_run_summary(
no_changes_message="\n||============= No portfolios changed. =============||", no_changes_message="||============= No portfolios changed. =============||",
debug=debug, debug=debug,
log_header="============= PORTFOLIOS =============", log_header="============= PORTFOLIOS =============",
skipped_header="----- SOME PORTFOLIOS WERENT CREATED (BUT OTHER RECORDS ARE STILL PROCESSED) -----", skipped_header="----- SOME PORTFOLIOS WERENT CREATED (BUT OTHER RECORDS ARE STILL PROCESSED) -----",
@ -265,7 +265,7 @@ class Command(BaseCommand):
display_as_str=True, display_as_str=True,
) )
self.suborganization_changes.print_script_run_summary( self.suborganization_changes.print_script_run_summary(
no_changes_message="\n||============= No suborganizations changed. =============||", no_changes_message="||============= No suborganizations changed. =============||",
debug=debug, debug=debug,
log_header="============= SUBORGANIZATIONS =============", log_header="============= SUBORGANIZATIONS =============",
skipped_header="----- SUBORGANIZATIONS SKIPPED (SAME NAME AS PORTFOLIO NAME) -----", skipped_header="----- SUBORGANIZATIONS SKIPPED (SAME NAME AS PORTFOLIO NAME) -----",
@ -507,7 +507,7 @@ class Command(BaseCommand):
# Clear the federal agency for started domain requests # Clear the federal agency for started domain requests
agency_name = normalize_string(domain_request.federal_agency.agency) agency_name = normalize_string(domain_request.federal_agency.agency)
portfolio_name = normalize_string(portfolio.organization_name) portfolio_name = normalize_string(portfolio.organization_name)
if not domain_request.portfolio and agency_name == portfolio_name: if agency_name == portfolio_name:
domain_request.federal_agency = None domain_request.federal_agency = None
logger.info(f"Set federal agency on started domain request '{domain_request}' to None.") logger.info(f"Set federal agency on started domain request '{domain_request}' to None.")
updated_domain_requests.add(domain_request) updated_domain_requests.add(domain_request)

View file

@ -1473,7 +1473,7 @@ class TestCreateFederalPortfolio(TestCase):
generic_org_type=DomainRequest.OrganizationChoices.CITY, generic_org_type=DomainRequest.OrganizationChoices.CITY,
federal_agency=self.federal_agency, federal_agency=self.federal_agency,
user=self.user, user=self.user,
organization_name="Testorg" organization_name="Testorg",
) )
self.domain_request.approve() self.domain_request.approve()
self.domain_info = DomainInformation.objects.filter(domain_request=self.domain_request).get() self.domain_info = DomainInformation.objects.filter(domain_request=self.domain_request).get()
@ -1875,7 +1875,9 @@ class TestCreateFederalPortfolio(TestCase):
UserDomainRole.objects.create(user=manager2, domain=self.domain, role=UserDomainRole.Roles.MANAGER) UserDomainRole.objects.create(user=manager2, domain=self.domain, role=UserDomainRole.Roles.MANAGER)
# Run the management command # Run the management command
self.run_create_federal_portfolio(agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True) self.run_create_federal_portfolio(
agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True
)
# Check that the portfolio was created # Check that the portfolio was created
self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency)
@ -1898,7 +1900,9 @@ class TestCreateFederalPortfolio(TestCase):
) )
# Run the management command # Run the management command
self.run_create_federal_portfolio(agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True) self.run_create_federal_portfolio(
agency_name=self.federal_agency.agency, parse_domains=True, parse_managers=True
)
# Check that the portfolio was created # Check that the portfolio was created
self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) self.portfolio = Portfolio.objects.get(federal_agency=self.federal_agency)
@ -1995,9 +1999,9 @@ class TestCreateFederalPortfolio(TestCase):
skip_existing_portfolios=True, skip_existing_portfolios=True,
) )
# Check that managers were added to the portfolio # Check that managers weren't added to the portfolio
permissions = UserPortfolioPermission.objects.filter(portfolio=self.portfolio, user__in=[manager1, manager2]) permissions = UserPortfolioPermission.objects.filter(portfolio=self.portfolio, user__in=[manager1, manager2])
self.assertEqual(permissions.count(), 2) self.assertEqual(permissions.count(), 0)
for perm in permissions: for perm in permissions:
self.assertIn(UserPortfolioRoleChoices.ORGANIZATION_MEMBER, perm.roles) self.assertIn(UserPortfolioRoleChoices.ORGANIZATION_MEMBER, perm.roles)