mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Internal: validate AnymailRecipientStatus at init
Catch invalid message_id and status when initializing AnymailRecipientStatus, so problems with ESP response are caught earlier (in individual backend parse_recipient_status, rather than base backend _send).
This commit is contained in:
@@ -42,6 +42,8 @@ Other
|
|||||||
|
|
||||||
* Move CI testing to GitHub Actions (and stop using Travis-CI).
|
* Move CI testing to GitHub Actions (and stop using Travis-CI).
|
||||||
|
|
||||||
|
* Internal: catch invalid recipient status earlier in ESP response parsing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
v8.1
|
v8.1
|
||||||
|
|||||||
@@ -85,6 +85,14 @@ class AnymailRecipientStatus:
|
|||||||
"""Information about an EmailMessage's send status for a single recipient"""
|
"""Information about an EmailMessage's send status for a single recipient"""
|
||||||
|
|
||||||
def __init__(self, message_id, status):
|
def __init__(self, message_id, status):
|
||||||
|
try:
|
||||||
|
# message_id must be something that can be put in a set
|
||||||
|
# (see AnymailStatus.set_recipient_status)
|
||||||
|
set([message_id])
|
||||||
|
except TypeError:
|
||||||
|
raise TypeError("Invalid message_id %r is not scalar type" % message_id)
|
||||||
|
if status is not None and status not in ANYMAIL_STATUSES:
|
||||||
|
raise ValueError("Invalid status %r" % status)
|
||||||
self.message_id = message_id # ESP message id
|
self.message_id = message_id # ESP message id
|
||||||
self.status = status # one of ANYMAIL_STATUSES, or None for not yet sent to ESP
|
self.status = status # one of ANYMAIL_STATUSES, or None for not yet sent to ESP
|
||||||
|
|
||||||
|
|||||||
@@ -76,3 +76,11 @@ class AnymailStatusTests(AnymailTestMixin, SimpleTestCase):
|
|||||||
self.assertIsNone(status.status)
|
self.assertIsNone(status.status)
|
||||||
self.assertIsNone(status.message_id)
|
self.assertIsNone(status.message_id)
|
||||||
self.assertEqual(repr(status), "AnymailStatus<status=None>")
|
self.assertEqual(repr(status), "AnymailStatus<status=None>")
|
||||||
|
|
||||||
|
def test_invalid_message_id(self):
|
||||||
|
with self.assertRaisesMessage(TypeError, "Invalid message_id"):
|
||||||
|
AnymailRecipientStatus(["id-list", "is-not-valid"], "queued")
|
||||||
|
|
||||||
|
def test_invalid_status(self):
|
||||||
|
with self.assertRaisesMessage(ValueError, "Invalid status"):
|
||||||
|
AnymailRecipientStatus("12345", "not-a-known-status")
|
||||||
|
|||||||
Reference in New Issue
Block a user