Skip to content

Commit

Permalink
lint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
rachidatecs committed Jul 25, 2024
1 parent 203c018 commit 2c4c528
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 44 deletions.
36 changes: 0 additions & 36 deletions src/registrar/forms/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,3 @@ def __init__(self, *args, **kwargs):
self.fields[field_name].required = True
self.fields["state_territory"].widget.attrs.pop("maxlength", None)
self.fields["zipcode"].widget.attrs.pop("maxlength", None)

# self.is_federal = self.instance.generic_org_type == DomainRequest.OrganizationChoices.FEDERAL
# self.is_tribal = self.instance.generic_org_type == DomainRequest.OrganizationChoices.TRIBAL

# field_to_disable = None
# if self.is_federal:
# field_to_disable = "federal_agency"
# elif self.is_tribal:
# field_to_disable = "organization_name"

# if field_to_disable is not None:
# DomainHelper.disable_field(self.fields[field_to_disable], disable_required=True)

# def save(self, commit=True):
# """Override the save() method of the BaseModelForm."""
# if self.has_changed():

# if self.is_federal and not self._field_unchanged("federal_agency"):
# raise ValueError("federal_agency cannot be modified when the generic_org_type is federal")
# elif self.is_tribal and not self._field_unchanged("organization_name"):
# raise ValueError("organization_name cannot be modified when the generic_org_type is tribal")

# else:
# super().save()

# def _field_unchanged(self, field_name) -> bool:
# """
# Checks if a specified field has not changed between the old value
# and the new value.

# The old value is grabbed from self.initial.
# The new value is grabbed from self.cleaned_data.
# """
# old_value = self.initial.get(field_name, None)
# new_value = self.cleaned_data.get(field_name, None)
# return old_value == new_value
5 changes: 0 additions & 5 deletions src/registrar/models/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
from .utility.time_stamped_model import TimeStampedModel


# def get_default_federal_agency():
# """returns non-federal agency"""
# return FederalAgency.objects.filter(agency="Non-Federal Agency").first()


class Portfolio(TimeStampedModel):
"""
Portfolio is used for organizing domains/domain-requests into
Expand Down
70 changes: 69 additions & 1 deletion src/registrar/tests/test_views_portfolio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import reverse
from api.tests.common import less_console_noise_decorator
from registrar.config import settings
from registrar.models.portfolio import Portfolio
from django_webtest import WebTest # type: ignore
from registrar.models import (
Expand All @@ -17,7 +18,7 @@
logger = logging.getLogger(__name__)


class TestPortfolioViews(TestWithUser, WebTest):
class TestPortfolio(TestWithUser, WebTest):
def setUp(self):
super().setUp()
self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
Expand Down Expand Up @@ -190,3 +191,70 @@ def tearDown(self):
DomainInformation.objects.all().delete()
Domain.objects.all().delete()
super().tearDown()


class TestPortfolioOrganization(TestPortfolio):

def test_portfolio_org_name(self):
"""Can load portfolio's org name page."""
with override_flag("organization_feature", active=True):
self.app.set_user(self.user.username)
self.user.portfolio = self.portfolio
self.user.portfolio_additional_permissions = [
User.UserPortfolioPermissionChoices.VIEW_PORTFOLIO,
User.UserPortfolioPermissionChoices.EDIT_PORTFOLIO,
]
self.user.save()
self.user.refresh_from_db()

page = self.app.get(reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk}))
self.assertContains(
page, "The name of your federal agency will be publicly listed as the domain registrant."
)

def test_domain_org_name_address_content(self):
"""Org name and address information appears on the page."""
with override_flag("organization_feature", active=True):
self.app.set_user(self.user.username)
self.user.portfolio = self.portfolio
self.user.portfolio_additional_permissions = [
User.UserPortfolioPermissionChoices.VIEW_PORTFOLIO,
User.UserPortfolioPermissionChoices.EDIT_PORTFOLIO,
]
self.user.save()
self.user.refresh_from_db()

self.portfolio.organization_name = "Hotel California"
self.portfolio.save()
page = self.app.get(reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk}))
# Once in the sidenav, once in the main nav, once in the form
self.assertContains(page, "Hotel California", count=3)

def test_domain_org_name_address_form(self):
"""Submitting changes works on the org name address page."""
with override_flag("organization_feature", active=True):
self.app.set_user(self.user.username)
self.user.portfolio = self.portfolio
self.user.portfolio_additional_permissions = [
User.UserPortfolioPermissionChoices.VIEW_PORTFOLIO,
User.UserPortfolioPermissionChoices.EDIT_PORTFOLIO,
]
self.user.save()
self.user.refresh_from_db()

self.portfolio.address_line1 = "1600 Penn Ave"
self.portfolio.save()
portfolio_org_name_page = self.app.get(
reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk})
)
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]

portfolio_org_name_page.form["address_line1"] = "6 Downing st"
portfolio_org_name_page.form["city"] = "London"

self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
success_result_page = portfolio_org_name_page.form.submit()
self.assertEqual(success_result_page.status_code, 200)

self.assertContains(success_result_page, "6 Downing st")
self.assertContains(success_result_page, "London")
5 changes: 3 additions & 2 deletions src/registrar/views/portfolios.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
def get_context_data(self, **kwargs):
"""Add additional context data to the template."""
context = super().get_context_data(**kwargs)
# no need to add portfolio to request context here
context["has_profile_feature_flag"] = flag_is_active(self.request, "profile_feature")
context["has_organization_feature_flag"] = flag_is_active(self.request, "organization_feature")
return context

def get_object(self, queryset=None):
"""Get the portfolio object based on the URL parameter."""
return get_object_or_404(Portfolio, id=self.kwargs.get("portfolio_id"))

def get_form_kwargs(self):
"""Include the instance in the form kwargs."""
kwargs = super().get_form_kwargs()
kwargs['instance'] = self.get_object()
kwargs["instance"] = self.get_object()
return kwargs

def get(self, request, *args, **kwargs):
Expand Down

0 comments on commit 2c4c528

Please sign in to comment.