Initialize email tests

This commit is contained in:
Erin Song 2025-01-29 15:10:06 -08:00
parent 691220698d
commit 59bda0b3cc
No known key found for this signature in database
3 changed files with 14 additions and 7 deletions

View file

@ -1375,7 +1375,7 @@ class UserDomainRoleAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Fixes a bug where non-superusers are redirected to the main page # Fixes a bug where non-superusers are redirected to the main page
def delete_view(self, request, object_id, extra_context=None): def delete_view(self, request, object_id, extra_context=None):
"""Custom delete_view implementation that specifies redirect behaviour""" """Custom delete_view implementation that specifies redirect behaviour"""
self.delete_confirmation_template = "django/admin/user_domain_role_delete_confirmation.html" self.delete_confirmation_template = "django/admin/user_domain_role_delete_confirmation.html"
response = super().delete_view(request, object_id, extra_context) response = super().delete_view(request, object_id, extra_context)
if isinstance(response, HttpResponseRedirect) and not request.user.has_perm("registrar.full_access_permission"): if isinstance(response, HttpResponseRedirect) and not request.user.has_perm("registrar.full_access_permission"):
@ -1517,7 +1517,6 @@ class DomainInvitationAdmin(BaseInvitationAdmin):
extra_context["tabtitle"] = "Domain invitations" extra_context["tabtitle"] = "Domain invitations"
# Get the filtered values # Get the filtered values
return super().changelist_view(request, extra_context=extra_context) return super().changelist_view(request, extra_context=extra_context)
def delete_view(self, request, object_id, extra_context=None): def delete_view(self, request, object_id, extra_context=None):
""" """

View file

@ -980,6 +980,14 @@ class TestDomainManagers(TestDomainOverview):
success_page = success_result.follow() success_page = success_result.follow()
self.assertContains(success_page, "Failed to send email.") self.assertContains(success_page, "Failed to send email.")
@boto3_mocking.patching
@less_console_noise_decorator
def test_domain_remove_manager(self):
"""Removing a domain manager sends notification email to other domain managers."""
print("self:", self)
response = self.client.get(reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.user.id}))
print("response: ", response)
@less_console_noise_decorator @less_console_noise_decorator
@patch("registrar.views.domain.send_domain_invitation_email") @patch("registrar.views.domain.send_domain_invitation_email")
def test_domain_invitation_created(self, mock_send_domain_email): def test_domain_invitation_created(self, mock_send_domain_email):

View file

@ -1335,16 +1335,16 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
# Is the user deleting themselves? If so, display a different message # Is the user deleting themselves? If so, display a different message
delete_self = self.request.user == self.object.user delete_self = self.request.user == self.object.user
# Email all domain managers that domain manager has been removed # Email all domain managers that domain manager has been removed
domain = self.object.domain domain = self.object.domain
context = { context = {
"domain": domain, "domain": domain,
"removed_by": self.request.user, "removed_by": self.request.user,
"manager_removed": self.object.user, "manager_removed": self.object.user,
"date": date.today(), "date": date.today(),
"changes": "Domain Manager" "changes": "Domain Manager",
} }
self.email_domain_managers( self.email_domain_managers(
domain, domain,
@ -1356,7 +1356,7 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
# Add a success message # Add a success message
messages.success(self.request, self.get_success_message(delete_self)) messages.success(self.request, self.get_success_message(delete_self))
return redirect(self.get_success_url()) return redirect(self.get_success_url())
def email_domain_managers(self, domain: Domain, template: str, subject_template: str, context={}): def email_domain_managers(self, domain: Domain, template: str, subject_template: str, context={}):
manager_pks = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER).values_list( manager_pks = UserDomainRole.objects.filter(domain=domain.pk, role=UserDomainRole.Roles.MANAGER).values_list(
"user", flat=True "user", flat=True
@ -1368,7 +1368,7 @@ class DomainDeleteUserView(UserDomainRolePermissionDeleteView):
send_templated_email( send_templated_email(
template, template,
subject_template, subject_template,
to_address=email, # type: ignore to_address=email,
context=context, context=context,
) )
except EmailSendingError: except EmailSendingError: