Linting and fix existing unit test

This commit is contained in:
zandercymatics 2024-08-09 13:53:54 -06:00
parent 2863e29d96
commit 4be1e3e29e
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 11 additions and 42 deletions

View file

@ -22,7 +22,7 @@ from epplibwrapper.errors import ErrorCode, RegistryError
from registrar.models.user_domain_role import UserDomainRole from registrar.models.user_domain_role import UserDomainRole
from waffle.admin import FlagAdmin from waffle.admin import FlagAdmin
from waffle.models import Sample, Switch from waffle.models import Sample, Switch
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
from registrar.views.utility.mixins import OrderableFieldsMixin from registrar.views.utility.mixins import OrderableFieldsMixin
from django.contrib.admin.views.main import ORDER_VAR from django.contrib.admin.views.main import ORDER_VAR

View file

@ -322,9 +322,10 @@ class SeniorOfficialContactForm(ContactForm):
JOIN = "senior_official" JOIN = "senior_official"
full_name = forms.CharField(label="Full name", required=False) full_name = forms.CharField(label="Full name", required=False)
def __init__(self, disable_fields=False, *args, **kwargs): def __init__(self, disable_fields=False, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self.instance: if self.instance:
self.fields["full_name"].initial = self.instance.get_formatted_name() self.fields["full_name"].initial = self.instance.get_formatted_name()

View file

@ -77,6 +77,7 @@ class PortfolioSeniorOfficialForm(forms.ModelForm):
JOIN = "senior_official" JOIN = "senior_official"
full_name = forms.CharField(label="Full name", required=False) full_name = forms.CharField(label="Full name", required=False)
class Meta: class Meta:
model = SeniorOfficial model = SeniorOfficial
fields = [ fields = [

View file

@ -8,4 +8,4 @@
{% if form.email.value is not None %} {% if form.email.value is not None %}
{% include "includes/input_read_only.html" with field=form.email %} {% include "includes/input_read_only.html" with field=form.email %}
{% endif %} {% endif %}

View file

@ -1192,14 +1192,14 @@ class TestDomainSeniorOfficial(TestDomainOverview):
self.assertTrue("disabled" in form[field_name].attrs) self.assertTrue("disabled" in form[field_name].attrs)
@less_console_noise_decorator @less_console_noise_decorator
def test_domain_edit_senior_official_federal(self): def test_domain_cannot_edit_senior_official_when_federal(self):
"""Tests that no edit can occur when the underlying domain is federal""" """Tests that no edit can occur when the underlying domain is federal"""
# Set the org type to federal # Set the org type to federal
self.domain_information.generic_org_type = DomainInformation.OrganizationChoices.FEDERAL self.domain_information.generic_org_type = DomainInformation.OrganizationChoices.FEDERAL
self.domain_information.save() self.domain_information.save()
# Add an SO. We can do this at the model level, just not the form level. # Add an SO
self.domain_information.senior_official = Contact( self.domain_information.senior_official = Contact(
first_name="Apple", last_name="Tester", title="CIO", email="nobody@igorville.gov" first_name="Apple", last_name="Tester", title="CIO", email="nobody@igorville.gov"
) )
@ -1210,43 +1210,10 @@ class TestDomainSeniorOfficial(TestDomainOverview):
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# Test if the form is populating data correctly self.assertContains(so_page, "Apple Tester")
so_form = so_page.forms[0] self.assertContains(so_page, "CIO")
self.assertContains(so_page, "nobody@igorville.gov")
test_cases = [ self.assertNotContains(so_page, "Save")
("first_name", "Apple"),
("last_name", "Tester"),
("title", "CIO"),
("email", "nobody@igorville.gov"),
]
self.assert_all_form_fields_have_expected_values(so_form, test_cases, test_for_disabled=True)
# Attempt to change data on each field. Because this domain is federal,
# this should not succeed.
so_form["first_name"] = "Orange"
so_form["last_name"] = "Smoothie"
so_form["title"] = "Cat"
so_form["email"] = "somebody@igorville.gov"
submission = so_form.submit()
# A 302 indicates this page underwent a redirect.
self.assertEqual(submission.status_code, 302)
followed_submission = submission.follow()
# Test the returned form for data accuracy. These values should be unchanged.
new_form = followed_submission.forms[0]
self.assert_all_form_fields_have_expected_values(new_form, test_cases, test_for_disabled=True)
# refresh domain information. Test these values in the DB.
self.domain_information.refresh_from_db()
# All values should be unchanged. These are defined manually for code clarity.
self.assertEqual("Apple", self.domain_information.senior_official.first_name)
self.assertEqual("Tester", self.domain_information.senior_official.last_name)
self.assertEqual("CIO", self.domain_information.senior_official.title)
self.assertEqual("nobody@igorville.gov", self.domain_information.senior_official.email)
@less_console_noise_decorator @less_console_noise_decorator
def test_domain_edit_senior_official_tribal(self): def test_domain_edit_senior_official_tribal(self):