friendlier error message

This commit is contained in:
David Kennedy 2024-12-30 10:56:04 -05:00
parent d36e2e2a63
commit d7493cc205
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
4 changed files with 8 additions and 9 deletions

View file

@ -618,7 +618,7 @@ class TestPortfolioInvitationAdmin(TestCase):
self.client.force_login(self.superuser)
# Mock the email sending function to raise MissingEmailError
mock_send_email.side_effect = MissingEmailError("Email-less Rachid")
mock_send_email.side_effect = MissingEmailError()
# Create an instance of the admin class
admin_instance = PortfolioInvitationAdmin(PortfolioInvitation, admin_site=None)
@ -640,7 +640,7 @@ class TestPortfolioInvitationAdmin(TestCase):
# Assert that messages.error was called with the correct message
mock_messages_error.assert_called_once_with(
request,
"Can't send invitation email. No email is associated with the account for 'Email-less Rachid'.",
"Can't send invitation email. No email is associated with your user account.",
)
@less_console_noise_decorator

View file

@ -2723,7 +2723,7 @@ class TestPortfolioInviteNewMemberView(TestWithUser, WebTest):
@patch("registrar.views.portfolios.send_portfolio_invitation_email")
def test_submit_new_member_raises_missing_email_error(self, mock_send_email):
"""Test when adding a new member and email_send method raises MissingEmailError."""
mock_send_email.side_effect = MissingEmailError(self.user.username)
mock_send_email.side_effect = MissingEmailError()
self.client.force_login(self.user)
@ -2751,7 +2751,7 @@ class TestPortfolioInviteNewMemberView(TestWithUser, WebTest):
# assert that messages contains message, "Could not send email invitation"
mock_error.assert_called_once_with(
response.wsgi_request,
"Can't send invitation email. No email is associated with the account for 'test_user'.",
"Can't send invitation email. No email is associated with your user account.",
)
# assert that portfolio invitation is not created
self.assertFalse(

View file

@ -38,7 +38,7 @@ def send_domain_invitation_email(email: str, requestor, domain, is_member_of_dif
# Check if the requestor is staff and has an email
if not requestor.is_staff:
if not requestor.email or requestor.email.strip() == "":
raise MissingEmailError(requestor.username)
raise MissingEmailError
else:
requestor_email = requestor.email
@ -98,7 +98,7 @@ def send_portfolio_invitation_email(email: str, requestor, portfolio):
# Check if the requestor is staff and has an email
if not requestor.is_staff:
if not requestor.email or requestor.email.strip() == "":
raise MissingEmailError(requestor.username)
raise MissingEmailError
else:
requestor_email = requestor.email

View file

@ -46,9 +46,8 @@ class AlreadyDomainInvitedError(InvitationError):
class MissingEmailError(InvitationError):
"""Raised when the requestor has no email associated with their account."""
def __init__(self, username):
super().__init__(f"Can't send invitation email. No email is associated with the account for '{username}'.")
self.username = username
def __init__(self):
super().__init__("Can't send invitation email. No email is associated with your user account.")
class OutsideOrgMemberError(ValueError):