Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion postmark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(
request_id: str | None = None,
):
super().__init__(message, error_code, http_status, request_id)
match = re.search(r"Found inactive addresses: ([^.]+)", message)
match = re.search(r"Found inactive addresses:\s*(.+?)\.(?:\s|$)", message)
self.inactive_recipients: list[str] = (
[a for addr in match.group(1).split(",") if (a := addr.strip())]
if match
Expand Down
40 changes: 40 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests for Postmark exception helpers."""

import pytest

from postmark.exceptions import InactiveRecipientException


@pytest.mark.parametrize(
("message", "expected"),
[
(
"Found inactive addresses: john@example.com. Emails to these addresses "
"are not accepted or delivered by Postmark.",
["john@example.com"],
),
(
"Found inactive addresses: john@example.com, jane@test.org. Emails to "
"these addresses are not accepted or delivered by Postmark.",
["john@example.com", "jane@test.org"],
),
(
"Found inactive addresses: a@example.co, b@example.io, c@example.net.",
["a@example.co", "b@example.io", "c@example.net"],
),
(
"Found inactive addresses:john@example.com.",
["john@example.com"],
),
(
"Inactive recipient.",
[],
),
],
)
def test_inactive_recipient_exception_parses_inactive_recipients(
message: str, expected: list[str]
):
exc = InactiveRecipientException(message, error_code=406, http_status=406)

assert exc.inactive_recipients == expected