mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 10:46:06 +02:00
lint and test
This commit is contained in:
parent
203c01843a
commit
2c4c528678
4 changed files with 72 additions and 44 deletions
|
@ -67,39 +67,3 @@ class PortfolioOrgAddressForm(forms.ModelForm):
|
|||
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
|
|
@ -6,11 +6,6 @@ from registrar.models.federal_agency import FederalAgency
|
|||
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
|
||||
|
|
|
@ -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 (
|
||||
|
@ -17,7 +18,7 @@ import logging
|
|||
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")
|
||||
|
@ -190,3 +191,70 @@ class TestPortfolioViews(TestWithUser, WebTest):
|
|||
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")
|
||||
|
|
|
@ -63,6 +63,7 @@ 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
|
||||
|
@ -70,11 +71,11 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
|
|||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue