mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Cleanup + (mostly) fix tests
This commit is contained in:
parent
4c84ad8456
commit
3441a3974f
7 changed files with 41 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -146,6 +146,7 @@ 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)
|
||||
|
|
|
@ -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:
|
||||
|
@ -922,6 +923,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)
|
||||
|
||||
if has_other_contacts:
|
||||
|
|
|
@ -1596,6 +1596,29 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
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):
|
||||
"""When transitioning to submitted from started or withdrawn on a domain request,
|
||||
|
@ -2290,6 +2313,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"status",
|
||||
"rejection_reason",
|
||||
"action_needed_reason",
|
||||
"action_needed_reason_email",
|
||||
"federal_agency",
|
||||
"portfolio",
|
||||
"creator",
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -104,7 +104,6 @@ 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
|
||||
|
@ -115,6 +114,4 @@ def get_action_needed_email(request, pk, reason):
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue