fixing tests

This commit is contained in:
David Kennedy 2025-01-17 20:03:04 -05:00
parent 463632baf7
commit 96618ee2bc
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 23 additions and 10 deletions

View file

@ -95,7 +95,6 @@ class RequestingEntityForm(RegistrarForm):
def clean_sub_organization(self): def clean_sub_organization(self):
"""On suborganization clean, set the suborganization value to None if the user is requesting """On suborganization clean, set the suborganization value to None if the user is requesting
a custom suborganization (as it doesn't exist yet)""" a custom suborganization (as it doesn't exist yet)"""
# If it's a new suborganization, return None (equivalent to selecting nothing) # If it's a new suborganization, return None (equivalent to selecting nothing)
if self.cleaned_data.get("is_requesting_new_suborganization"): if self.cleaned_data.get("is_requesting_new_suborganization"):
return None return None
@ -129,7 +128,6 @@ class RequestingEntityForm(RegistrarForm):
# Retrieve sub_organization and store in _original_suborganization # Retrieve sub_organization and store in _original_suborganization
suborganization = data.get("portfolio_requesting_entity-sub_organization") suborganization = data.get("portfolio_requesting_entity-sub_organization")
self._original_suborganization = suborganization self._original_suborganization = suborganization
# If the original value was "other", clear it for validation # If the original value was "other", clear it for validation
if self._original_suborganization == "other": if self._original_suborganization == "other":
data["portfolio_requesting_entity-sub_organization"] = "" data["portfolio_requesting_entity-sub_organization"] = ""
@ -171,7 +169,6 @@ class RequestingEntityForm(RegistrarForm):
requesting_entity_is_suborganization = self.data.get( requesting_entity_is_suborganization = self.data.get(
"portfolio_requesting_entity-requesting_entity_is_suborganization" "portfolio_requesting_entity-requesting_entity_is_suborganization"
) )
if requesting_entity_is_suborganization == "True": if requesting_entity_is_suborganization == "True":
if is_requesting_new_suborganization: if is_requesting_new_suborganization:
if not cleaned_data.get("requested_suborganization") and "requested_suborganization" not in self.errors: if not cleaned_data.get("requested_suborganization") and "requested_suborganization" not in self.errors:

View file

@ -2879,7 +2879,7 @@ class TestRequestingEntity(WebTest):
form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True
form["portfolio_requesting_entity-is_requesting_new_suborganization"] = True form["portfolio_requesting_entity-is_requesting_new_suborganization"] = True
form["portfolio_requesting_entity-sub_organization"] = "" form["portfolio_requesting_entity-sub_organization"] = "other"
form["portfolio_requesting_entity-requested_suborganization"] = "moon" form["portfolio_requesting_entity-requested_suborganization"] = "moon"
form["portfolio_requesting_entity-suborganization_city"] = "kepler" form["portfolio_requesting_entity-suborganization_city"] = "kepler"
@ -2933,7 +2933,7 @@ class TestRequestingEntity(WebTest):
@override_flag("organization_feature", active=True) @override_flag("organization_feature", active=True)
@override_flag("organization_requests", active=True) @override_flag("organization_requests", active=True)
@less_console_noise_decorator # @less_console_noise_decorator
def test_requesting_entity_page_errors(self): def test_requesting_entity_page_errors(self):
"""Tests that we get the expected form errors on requesting entity""" """Tests that we get the expected form errors on requesting entity"""
domain_request = completed_domain_request(user=self.user, portfolio=self.portfolio) domain_request = completed_domain_request(user=self.user, portfolio=self.portfolio)
@ -2942,18 +2942,34 @@ class TestRequestingEntity(WebTest):
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)
# For 2 the tests below, it is required to submit a form without submitting a value
# for the select/combobox. WebTest will not do this; by default, WebTest will submit
# the first choice in a select. So, need to manipulate the form to remove the
# particular select/combobox that will not be submitted, and then post the form.
form_action = f"/request/{domain_request.pk}/portfolio_requesting_entity/"
# Test missing suborganization selection # Test missing suborganization selection
form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True
form["portfolio_requesting_entity-sub_organization"] = "" form["portfolio_requesting_entity-is_requesting_new_suborganization"] = False
# remove sub_organization from the form submission
response = form.submit() form_data = form.submit_fields()
form_data = [(key, value) for key, value in form_data if key != "portfolio_requesting_entity-sub_organization"]
response = self.app.post(form_action, dict(form_data))
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.assertContains(response, "Suborganization is required.", status_code=200) self.assertContains(response, "Suborganization is required.", status_code=200)
# Test missing custom suborganization details # Test missing custom suborganization details
form["portfolio_requesting_entity-requesting_entity_is_suborganization"] = True
form["portfolio_requesting_entity-is_requesting_new_suborganization"] = True form["portfolio_requesting_entity-is_requesting_new_suborganization"] = True
response = form.submit() form["portfolio_requesting_entity-sub_organization"] = "other"
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) # remove suborganization_state_territory from the form submission
form_data = form.submit_fields()
form_data = [
(key, value)
for key, value in form_data
if key != "portfolio_requesting_entity-suborganization_state_territory"
]
response = self.app.post(form_action, dict(form_data))
self.assertContains(response, "Enter the name of your suborganization.", status_code=200) self.assertContains(response, "Enter the name of your suborganization.", status_code=200)
self.assertContains(response, "Enter the city where your suborganization is located.", status_code=200) self.assertContains(response, "Enter the city where your suborganization is located.", status_code=200)
self.assertContains( self.assertContains(