-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2548 from cisagov/meoward/2484-dynamic-portfolio-…
…fields Ticket #2484: Dynamic portfolio fields
- Loading branch information
Showing
11 changed files
with
337 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/registrar/templates/django/admin/portfolio_change_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.urls import reverse | ||
from django.test import TestCase, Client | ||
from registrar.models import FederalAgency, SeniorOfficial, User | ||
from django.contrib.auth import get_user_model | ||
from registrar.tests.common import create_superuser, create_user | ||
|
||
|
||
class GetSeniorOfficialJsonTest(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
p = "password" | ||
self.user = get_user_model().objects.create_user(username="testuser", password=p) | ||
|
||
self.superuser = create_superuser() | ||
self.analyst_user = create_user() | ||
|
||
self.agency = FederalAgency.objects.create(agency="Test Agency") | ||
self.senior_official = SeniorOfficial.objects.create( | ||
first_name="John", last_name="Doe", title="Director", federal_agency=self.agency | ||
) | ||
|
||
self.api_url = reverse("get-senior-official-from-federal-agency-json") | ||
|
||
def tearDown(self): | ||
User.objects.all().delete() | ||
SeniorOfficial.objects.all().delete() | ||
FederalAgency.objects.all().delete() | ||
|
||
def test_get_senior_official_json_authenticated_superuser(self): | ||
"""Test that a superuser can fetch the senior official information.""" | ||
p = "adminpass" | ||
self.client.login(username="superuser", password=p) | ||
response = self.client.get(self.api_url, {"agency_name": "Test Agency"}) | ||
self.assertEqual(response.status_code, 200) | ||
data = response.json() | ||
self.assertEqual(data["id"], self.senior_official.id) | ||
self.assertEqual(data["first_name"], "John") | ||
self.assertEqual(data["last_name"], "Doe") | ||
self.assertEqual(data["title"], "Director") | ||
|
||
def test_get_senior_official_json_authenticated_analyst(self): | ||
"""Test that an analyst user can fetch the senior official's information.""" | ||
p = "userpass" | ||
self.client.login(username="staffuser", password=p) | ||
response = self.client.get(self.api_url, {"agency_name": "Test Agency"}) | ||
self.assertEqual(response.status_code, 200) | ||
data = response.json() | ||
self.assertEqual(data["id"], self.senior_official.id) | ||
self.assertEqual(data["first_name"], "John") | ||
self.assertEqual(data["last_name"], "Doe") | ||
self.assertEqual(data["title"], "Director") | ||
|
||
def test_get_senior_official_json_unauthenticated(self): | ||
"""Test that an unauthenticated user receives a 403 with an error message.""" | ||
p = "password" | ||
self.client.login(username="testuser", password=p) | ||
response = self.client.get(self.api_url, {"agency_name": "Test Agency"}) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
def test_get_senior_official_json_not_found(self): | ||
"""Test that a request for a non-existent agency returns a 404 with an error message.""" | ||
p = "adminpass" | ||
self.client.login(username="superuser", password=p) | ||
response = self.client.get(self.api_url, {"agency_name": "Non-Federal Agency"}) | ||
self.assertEqual(response.status_code, 404) | ||
data = response.json() | ||
self.assertEqual(data["error"], "Senior Official not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2266,3 +2266,57 @@ def test_form_complete(self): | |
self.domain_request.generic_org_type = None | ||
self.domain_request.save() | ||
self.assertFalse(self.domain_request._form_complete(request)) | ||
|
||
|
||
class TestPortfolio(TestCase): | ||
def setUp(self): | ||
self.user, _ = User.objects.get_or_create( | ||
username="[email protected]", email="[email protected]", first_name="Lava", last_name="World" | ||
) | ||
super().setUp() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
Portfolio.objects.all().delete() | ||
User.objects.all().delete() | ||
|
||
def test_urbanization_field_resets_when_not_puetro_rico(self): | ||
"""The urbanization field should only be populated when the state is puetro rico. | ||
Otherwise, this field should be empty.""" | ||
# Start out as PR, then change the field | ||
portfolio = Portfolio.objects.create( | ||
creator=self.user, | ||
organization_name="Test Portfolio", | ||
state_territory=DomainRequest.StateTerritoryChoices.PUERTO_RICO, | ||
urbanization="test", | ||
) | ||
|
||
self.assertEqual(portfolio.urbanization, "test") | ||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO) | ||
|
||
portfolio.state_territory = DomainRequest.StateTerritoryChoices.ALABAMA | ||
portfolio.save() | ||
|
||
self.assertEqual(portfolio.urbanization, None) | ||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.ALABAMA) | ||
|
||
def test_can_add_urbanization_field(self): | ||
"""Ensures that you can populate the urbanization field when conditions are right""" | ||
# Create a portfolio that cannot have this field | ||
portfolio = Portfolio.objects.create( | ||
creator=self.user, | ||
organization_name="Test Portfolio", | ||
state_territory=DomainRequest.StateTerritoryChoices.ALABAMA, | ||
urbanization="test", | ||
) | ||
|
||
# Implicitly check if this gets cleared on create. It should. | ||
self.assertEqual(portfolio.urbanization, None) | ||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.ALABAMA) | ||
|
||
portfolio.state_territory = DomainRequest.StateTerritoryChoices.PUERTO_RICO | ||
portfolio.urbanization = "test123" | ||
portfolio.save() | ||
|
||
self.assertEqual(portfolio.urbanization, "test123") | ||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.