mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 20:18:38 +02:00
fix tests
This commit is contained in:
parent
86f520c3f6
commit
866204cb8d
4 changed files with 40 additions and 4 deletions
|
@ -1951,11 +1951,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
|
||||
allowed = models.AllowedEmail.is_allowed_email(email)
|
||||
error_message = f"Could not send email. The email '{email}' does not exist within the whitelist."
|
||||
success_message = f"An email to '{email}' was sent!"
|
||||
if not allowed:
|
||||
messages.warning(request, error_message)
|
||||
else:
|
||||
messages.success(request, success_message)
|
||||
|
||||
def _handle_status_change(self, request, obj, original_obj):
|
||||
"""
|
||||
|
|
|
@ -22,6 +22,7 @@ from registrar.models import (
|
|||
Contact,
|
||||
Website,
|
||||
SeniorOfficial,
|
||||
AllowedEmail,
|
||||
)
|
||||
from .common import (
|
||||
MockSESClient,
|
||||
|
@ -52,6 +53,10 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
tests have available staffuser, superuser, client, admin and test_helper
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super().tearDownClass()
|
||||
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
super().setUpClass()
|
||||
|
@ -84,6 +89,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
def tearDownClass(self):
|
||||
super().tearDownClass()
|
||||
User.objects.all().delete()
|
||||
AllowedEmail.objects.all().delete()
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_request_senior_official_is_alphabetically_sorted(self):
|
||||
|
@ -597,7 +603,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
):
|
||||
"""Helper method for the email test cases.
|
||||
email_index is the index of the email in mock_client."""
|
||||
|
||||
allowed_email, _ = AllowedEmail.objects.get_or_create(email=email_address)
|
||||
allowed_bcc_email, _ = AllowedEmail.objects.get_or_create(email=bcc_email_address)
|
||||
with less_console_noise():
|
||||
# Access the arguments passed to send_email
|
||||
call_args = self.mock_client.EMAILS_SENT
|
||||
|
@ -624,6 +631,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
if bcc_email_address:
|
||||
bcc_email = kwargs["Destination"]["BccAddresses"][0]
|
||||
self.assertEqual(bcc_email, bcc_email_address)
|
||||
|
||||
allowed_email.delete()
|
||||
allowed_bcc_email.delete()
|
||||
|
||||
@override_settings(IS_PRODUCTION=True)
|
||||
@less_console_noise_decorator
|
||||
|
@ -1686,6 +1696,8 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
# Patch Domain.is_active and django.contrib.messages.error simultaneously
|
||||
stack.enter_context(patch.object(Domain, "is_active", custom_is_active))
|
||||
stack.enter_context(patch.object(messages, "error"))
|
||||
stack.enter_context(patch.object(messages, "warning"))
|
||||
stack.enter_context(patch.object(messages, "success"))
|
||||
|
||||
domain_request.status = another_state
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from waffle.testutils import override_flag
|
|||
from registrar.utility import email
|
||||
from registrar.utility.email import send_templated_email
|
||||
from .common import completed_domain_request
|
||||
from registrar.models import AllowedEmail
|
||||
|
||||
from api.tests.common import less_console_noise_decorator
|
||||
from datetime import datetime
|
||||
|
@ -14,9 +15,32 @@ import boto3_mocking # type: ignore
|
|||
|
||||
|
||||
class TestEmails(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
allowed_emails = [
|
||||
AllowedEmail(email="doesnotexist@igorville.com"),
|
||||
AllowedEmail(email="testy@town.com"),
|
||||
AllowedEmail(email="mayor@igorville.gov"),
|
||||
AllowedEmail(email="testy2@town.com"),
|
||||
AllowedEmail(email="cisaRep@igorville.gov"),
|
||||
AllowedEmail(email="sender@example.com"),
|
||||
AllowedEmail(email="recipient@example.com"),
|
||||
]
|
||||
AllowedEmail.objects.bulk_create(allowed_emails)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super().tearDownClass()
|
||||
AllowedEmail.objects.all().delete()
|
||||
|
||||
def setUp(self):
|
||||
self.mock_client_class = MagicMock()
|
||||
self.mock_client = self.mock_client_class.return_value
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
|
||||
@boto3_mocking.patching
|
||||
@override_flag("disable_email_sending", active=True)
|
||||
|
|
|
@ -27,6 +27,7 @@ from registrar.models import (
|
|||
Domain,
|
||||
DomainInformation,
|
||||
DomainInvitation,
|
||||
AllowedEmail,
|
||||
Contact,
|
||||
PublicContact,
|
||||
Host,
|
||||
|
@ -460,6 +461,7 @@ class TestDomainManagers(TestDomainOverview):
|
|||
"""Inviting a non-existent user sends them an email."""
|
||||
# make sure there is no user with this email
|
||||
email_address = "mayor@igorville.gov"
|
||||
allowed_email, _ = AllowedEmail.objects.get_or_create(email=email_address)
|
||||
User.objects.filter(email=email_address).delete()
|
||||
|
||||
self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain)
|
||||
|
@ -479,6 +481,7 @@ class TestDomainManagers(TestDomainOverview):
|
|||
Destination={"ToAddresses": [email_address]},
|
||||
Content=ANY,
|
||||
)
|
||||
allowed_email.delete()
|
||||
|
||||
@boto3_mocking.patching
|
||||
@less_console_noise_decorator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue