mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 20:49:41 +02:00
Unit tests and documentation
This commit is contained in:
parent
9052d9ed3f
commit
188c99a169
4 changed files with 117 additions and 12 deletions
|
@ -918,3 +918,36 @@ Example (only requests): `./manage.py create_federal_portfolio --branch "executi
|
||||||
- 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 #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,
|
||||||
you must specify at least one to run this script.
|
you must specify at least one to run this script.
|
||||||
|
|
||||||
|
|
||||||
|
## Populate requested suborg
|
||||||
|
This script populates the "requested suborganization" fields on DomainRequest.
|
||||||
|
These fields are: requested_suborganization, suborganization_city, suborganization_state_territory.
|
||||||
|
|
||||||
|
This is done by pulling from organization_name, city, and state_territory.
|
||||||
|
The script will only parse records with a portfolio but no suborganization attached to it.
|
||||||
|
|
||||||
|
### Running on sandboxes
|
||||||
|
|
||||||
|
#### Step 1: Login to CloudFoundry
|
||||||
|
```cf login -a api.fr.cloud.gov --sso```
|
||||||
|
|
||||||
|
#### Step 2: SSH into your environment
|
||||||
|
```cf ssh getgov-{space}```
|
||||||
|
|
||||||
|
Example: `cf ssh getgov-za`
|
||||||
|
|
||||||
|
#### Step 3: Create a shell instance
|
||||||
|
```/tmp/lifecycle/shell```
|
||||||
|
|
||||||
|
#### Step 4: Upload your csv to the desired sandbox
|
||||||
|
[Follow these steps](#use-scp-to-transfer-data-to-sandboxes) to upload the federal_cio csv to a sandbox of your choice.
|
||||||
|
|
||||||
|
#### Step 5: Running the script
|
||||||
|
To create a specific portfolio:
|
||||||
|
```./manage.py populate_requested_suborg```
|
||||||
|
|
||||||
|
### Running locally
|
||||||
|
|
||||||
|
#### Step 1: Running the script
|
||||||
|
```docker-compose exec app ./manage.py populate_requested_suborg```
|
||||||
|
|
|
@ -7,7 +7,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand, PopulateScriptTemplate):
|
class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
help = "Loops through each domain request object and populates the last_status_update and first_submitted_date"
|
help = "Loops through each domain request object and populates requested suborg info"
|
||||||
|
|
||||||
def handle(self, **kwargs):
|
def handle(self, **kwargs):
|
||||||
"""Loops through each DomainRequest object and populates
|
"""Loops through each DomainRequest object and populates
|
||||||
|
@ -26,12 +26,3 @@ class Command(BaseCommand, PopulateScriptTemplate):
|
||||||
f"sub_city: {record.city}, suborg_state_territory: {record.state_territory}."
|
f"sub_city: {record.city}, suborg_state_territory: {record.state_territory}."
|
||||||
)
|
)
|
||||||
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, message)
|
TerminalHelper.colorful_logger(logger.info, TerminalColors.OKBLUE, message)
|
||||||
|
|
||||||
def should_skip_record(self, record: DomainRequest) -> bool:
|
|
||||||
"""Skips record update if we're missing org name, city, and state territory."""
|
|
||||||
required_fields = [
|
|
||||||
record.organization_name,
|
|
||||||
record.city,
|
|
||||||
record.state_territory
|
|
||||||
]
|
|
||||||
return not all(bool(field) for field in required_fields)
|
|
||||||
|
|
|
@ -1032,6 +1032,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,
|
||||||
|
@ -1076,7 +1078,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,
|
||||||
|
@ -1085,6 +1087,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:
|
||||||
|
|
|
@ -32,7 +32,7 @@ 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
|
from .common import MockEppLib, create_user, less_console_noise, completed_domain_request, MockSESClient
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
|
|
||||||
|
@ -1731,3 +1731,78 @@ class TestCreateFederalPortfolio(TestCase):
|
||||||
self.assertEqual(existing_portfolio.organization_name, self.federal_agency.agency)
|
self.assertEqual(existing_portfolio.organization_name, self.federal_agency.agency)
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPopulateRequestedSuborg(MockEppLib):
|
||||||
|
"""Tests for the populate_requested_suborg script"""
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def setUp(self):
|
||||||
|
"""Creates test domain requests with various states"""
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self.user = create_user()
|
||||||
|
# Create a portfolio
|
||||||
|
self.portfolio = Portfolio.objects.create(organization_name="Test Portfolio", creator=self.user)
|
||||||
|
|
||||||
|
# Create a domain request with all required fields
|
||||||
|
self.complete_request = completed_domain_request(
|
||||||
|
name="complete.gov",
|
||||||
|
organization_name="Complete Org",
|
||||||
|
city="Washington",
|
||||||
|
state_territory="DC",
|
||||||
|
portfolio=self.portfolio,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a request that already has a suborganization
|
||||||
|
self.suborg = Suborganization.objects.create(name="Existing Suborg", portfolio=self.portfolio)
|
||||||
|
self.existing_suborg_request = completed_domain_request(
|
||||||
|
name="existing.gov",
|
||||||
|
organization_name="Existing Org",
|
||||||
|
city="New York",
|
||||||
|
state_territory="NY",
|
||||||
|
portfolio=self.portfolio,
|
||||||
|
sub_organization=self.suborg,
|
||||||
|
)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""Cleans up test data"""
|
||||||
|
super().tearDown()
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
Suborganization.objects.all().delete()
|
||||||
|
Portfolio.objects.all().delete()
|
||||||
|
User.objects.all().delete()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def run_populate_requested_suborg(self):
|
||||||
|
"""Executes the populate_requested_suborg command"""
|
||||||
|
with patch(
|
||||||
|
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit",
|
||||||
|
return_value=True,
|
||||||
|
):
|
||||||
|
call_command("populate_requested_suborg")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_populate_requested_suborg_complete_request(self):
|
||||||
|
"""Tests that complete requests are updated correctly"""
|
||||||
|
self.run_populate_requested_suborg()
|
||||||
|
|
||||||
|
self.complete_request.refresh_from_db()
|
||||||
|
|
||||||
|
# Verify fields were populated correctly
|
||||||
|
self.assertEqual(self.complete_request.requested_suborganization, "Complete Org")
|
||||||
|
self.assertEqual(self.complete_request.suborganization_city, "Washington")
|
||||||
|
self.assertEqual(self.complete_request.suborganization_state_territory, "DC")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_populate_requested_suborg_existing_suborg(self):
|
||||||
|
"""Tests that requests with existing suborgs are skipped"""
|
||||||
|
self.run_populate_requested_suborg()
|
||||||
|
|
||||||
|
self.existing_suborg_request.refresh_from_db()
|
||||||
|
|
||||||
|
# Verify the request wasn't modified
|
||||||
|
self.assertEqual(self.existing_suborg_request.sub_organization, self.suborg)
|
||||||
|
self.assertIsNone(self.existing_suborg_request.requested_suborganization)
|
||||||
|
self.assertIsNone(self.existing_suborg_request.suborganization_city)
|
||||||
|
self.assertIsNone(self.existing_suborg_request.suborganization_state_territory)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue