mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Fix test + some minor cleanup stuff
This commit is contained in:
parent
ec1df251b8
commit
dbfc54837a
4 changed files with 39 additions and 7 deletions
|
@ -704,6 +704,7 @@ class DomainRequest(TimeStampedModel):
|
|||
# We should never send an email if no reason was specified.
|
||||
# Additionally, Don't send out emails for reasons that shouldn't send them.
|
||||
if status_info.get("reason") is None or status_info.get("reason") in status_info.get("excluded_reasons"):
|
||||
logger.warning("send_custom_status_update_email() => Tried sending a status email without a reason.")
|
||||
return
|
||||
|
||||
# Only send out an email if the underlying reason itself changed or if no email was sent previously.
|
||||
|
@ -1064,8 +1065,15 @@ class DomainRequest(TimeStampedModel):
|
|||
def reject(self):
|
||||
"""Reject an domain request that has been submitted.
|
||||
|
||||
This action is logged.
|
||||
|
||||
This action cleans up the action needed status if moving away from action needed.
|
||||
|
||||
As side effects this will delete the domain and domain_information
|
||||
(will cascade), and send an email notification using send_custom_status_update_email.
|
||||
(will cascade) when they exist.
|
||||
|
||||
Afterwards, we send out an email for reject in def save().
|
||||
See the function send_custom_status_update_email.
|
||||
"""
|
||||
|
||||
if self.status == self.DomainRequestStatus.APPROVED:
|
||||
|
|
|
@ -221,9 +221,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
</div>
|
||||
|
||||
{% if original_object.action_needed_reason_email %}
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="{{original_object.action_needed_reason_email}}">
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="{{original_object.action_needed_reason_email}}">
|
||||
{% else %}
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="None">
|
||||
<input id="last-sent-action-needed-email-content" class="display-none" value="None">
|
||||
{% endif %}
|
||||
|
||||
{% elif field.field.name == "rejection_reason_email" %}
|
||||
|
@ -310,9 +310,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
</div>
|
||||
|
||||
{% if original_object.rejection_reason_email %}
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="{{original_object.rejection_reason_email}}">
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="{{original_object.rejection_reason_email}}">
|
||||
{% else %}
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="None">
|
||||
<input id="last-sent-rejection-email-content" class="display-none" value="None">
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ field.field }}
|
||||
|
|
|
@ -637,7 +637,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
with less_console_noise():
|
||||
# Access the arguments passed to send_email
|
||||
call_args = self.mock_client.EMAILS_SENT
|
||||
logger.info(f"what are the call args? {call_args}")
|
||||
kwargs = call_args[email_index]["kwargs"]
|
||||
|
||||
# Retrieve the email details from the arguments
|
||||
|
|
|
@ -267,7 +267,6 @@ class TestDomainRequest(TestCase):
|
|||
domain_request.submit()
|
||||
self.assertEqual(domain_request.status, domain_request.DomainRequestStatus.SUBMITTED)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def check_email_sent(
|
||||
self, domain_request, msg, action, expected_count, expected_content=None, expected_email="mayor@igorville.com"
|
||||
):
|
||||
|
@ -278,6 +277,7 @@ class TestDomainRequest(TestCase):
|
|||
# Perform the specified action
|
||||
action_method = getattr(domain_request, action)
|
||||
action_method()
|
||||
domain_request.save()
|
||||
|
||||
# Check if an email was sent
|
||||
sent_emails = [
|
||||
|
@ -337,6 +337,31 @@ class TestDomainRequest(TestCase):
|
|||
domain_request, msg, "withdraw", 1, expected_content="withdrawn", expected_email=user.email
|
||||
)
|
||||
|
||||
def test_reject_sends_email(self):
|
||||
"Create a domain request and reject it and see if email was sent."
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED, user=user)
|
||||
expected_email=user.email
|
||||
email_allowed, _ = AllowedEmail.objects.get_or_create(email=expected_email)
|
||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||
domain_request.reject()
|
||||
domain_request.rejection_reason = domain_request.RejectionReasons.CONTACTS_NOT_VERIFIED
|
||||
domain_request.rejection_reason_email = "test"
|
||||
domain_request.save()
|
||||
|
||||
# Check if an email was sent
|
||||
sent_emails = [
|
||||
email
|
||||
for email in MockSESClient.EMAILS_SENT
|
||||
if expected_email in email["kwargs"]["Destination"]["ToAddresses"]
|
||||
]
|
||||
self.assertEqual(len(sent_emails), 1)
|
||||
|
||||
email_content = sent_emails[0]["kwargs"]["Content"]["Simple"]["Body"]["Text"]["Data"]
|
||||
self.assertIn("test", email_content)
|
||||
|
||||
email_allowed.delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_reject_with_prejudice_does_not_send_email(self):
|
||||
msg = "Create a domain request and reject it with prejudice and see if email was sent."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue