Cleanup + (mostly) fix tests

This commit is contained in:
zandercymatics 2024-06-20 12:44:22 -06:00
parent 4c84ad8456
commit 3441a3974f
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
7 changed files with 41 additions and 12 deletions

View file

@ -213,7 +213,11 @@ urlpatterns = [
),
path("get-domains-json/", get_domains_json, name="get_domains_json"),
path("get-domain-requests-json/", get_domain_requests_json, name="get_domain_requests_json"),
path("get-domain-requests-json/<int:pk>/action-needed-email/<str:reason>", get_action_needed_email, name="get_action_needed_email"),
path(
"get-domain-requests-json/<int:pk>/action-needed-email/<str:reason>",
get_action_needed_email,
name="get_action_needed_email",
),
]
# Djangooidc strips out context data from that context, so we define a custom error

View file

@ -557,7 +557,6 @@ class DomainRequest(TimeStampedModel):
blank=True,
)
def get_action_needed_reason_default_email_text(self, action_needed_reason: str):
"""Returns the default email associated with the given action needed reason"""
if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER:
@ -579,10 +578,9 @@ class DomainRequest(TimeStampedModel):
return {
"subject_text": subject_template.render(context=context),
"email_body_text": template.render(context=context)
"email_body_text": template.render(context=context),
}
def sync_organization_type(self):
"""
Updates the organization_type (without saving) to match

View file

@ -146,11 +146,12 @@ def format_phone(value):
return phone_number.as_national
return value
@register.filter
def strip_beginning_newline_and_spaces(value):
"""Removes any newline characters (and spaces)
"""Removes any newline characters (and spaces)
on the first line of a given string"""
if value and isinstance(value, str):
return value.lstrip("\n").lstrip(" ")
else:
return value
return value

View file

@ -858,6 +858,7 @@ def completed_domain_request( # noqa
is_election_board=False,
organization_type=None,
federal_agency=None,
action_needed_reason=None,
):
"""A completed domain request."""
if not user:
@ -921,6 +922,9 @@ def completed_domain_request( # noqa
if organization_type:
domain_request_kwargs["organization_type"] = organization_type
if action_needed_reason:
domain_request_kwargs["action_needed_reason"] = action_needed_reason
domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs)

View file

@ -1595,6 +1595,29 @@ class TestDomainRequestAdmin(MockEppLib):
# Test Submitted Status Again from in ACTION_NEEDED, no new email should be sent
self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.SUBMITTED)
self.assertEqual(len(self.mock_client.EMAILS_SENT), 3)
@less_console_noise_decorator
def test_model_displays_action_needed_email(self):
"""Tests if the action needed email is visible for Domain Requests"""
_domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.ACTION_NEEDED,
action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME
)
p = "userpass"
self.client.login(username="staffuser", password=p)
response = self.client.get(
"/admin/registrar/domainrequest/{}/change/".format(_domain_request.pk),
follow=True,
)
self.assertContains(response, "DOMAIN NAME DOES NOT MEET .GOV REQUIREMENTS")
_domain_request.action_needed_reason = DomainRequest.ActionNeededReasons.OTHER
_domain_request.save()
self.assertContains(response, "No email will be sent")
@override_settings(IS_PRODUCTION=True)
def test_save_model_sends_submitted_email_with_bcc_on_prod(self):
@ -2290,6 +2313,7 @@ class TestDomainRequestAdmin(MockEppLib):
"status",
"rejection_reason",
"action_needed_reason",
"action_needed_reason_email",
"federal_agency",
"portfolio",
"creator",

View file

@ -24,6 +24,7 @@ SAMPLE_KWARGS = {
"object_id": "3",
"domain": "whitehouse.gov",
"user_pk": "1",
"reason": "bad_name",
}
# Our test suite will ignore some namespaces.

View file

@ -104,17 +104,14 @@ def get_domain_requests_json(request):
)
@login_required
def get_action_needed_email(request, pk, reason):
has_access = request.user.is_staff or request.user.is_superuser
# TODO also check the perm group
# TODO also check the perm group
if not has_access:
raise PermissionDenied("You do not have permission to access this resource.")
domain_request = DomainRequest.objects.filter(id=pk).first()
reason_dict = domain_request.get_action_needed_reason_default_email_text(reason)
return JsonResponse(
reason_dict
)
return JsonResponse(reason_dict)