Skip to content

Commit 33319e6

Browse files
Add support for bulk sending mode in Mailtrap client
Introduce a new `bulk` mode in the Mailtrap client, setting a dedicated `BULK_HOST` for bulk operations. Updated validation logic to prevent conflicts between bulk and sandbox modes. Added corresponding test cases to ensure correct functionality and URL generation.
1 parent 8cd83b7 commit 33319e6

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

mailtrap/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@
1515
class MailtrapClient:
1616
DEFAULT_HOST = "send.api.mailtrap.io"
1717
DEFAULT_PORT = 443
18+
BULK_HOST = "bulk.api.mailtrap.io"
1819
SANDBOX_HOST = "sandbox.api.mailtrap.io"
1920

2021
def __init__(
2122
self,
2223
token: str,
2324
api_host: Optional[str] = None,
2425
api_port: int = DEFAULT_PORT,
26+
bulk: bool = False,
2527
sandbox: bool = False,
2628
inbox_id: Optional[str] = None,
2729
) -> None:
2830
self.token = token
2931
self.api_host = api_host
3032
self.api_port = api_port
33+
self.bulk = bulk
3134
self.sandbox = sandbox
3235
self.inbox_id = inbox_id
3336

@@ -72,6 +75,8 @@ def _host(self) -> str:
7275
return self.api_host
7376
if self.sandbox:
7477
return self.SANDBOX_HOST
78+
if self.bulk:
79+
return self.BULK_HOST
7580
return self.DEFAULT_HOST
7681

7782
@staticmethod
@@ -92,3 +97,6 @@ def _validate_itself(self) -> None:
9297
raise ClientConfigurationError(
9398
"`inbox_id` is not allowed in non-sandbox mode"
9499
)
100+
101+
if self.bulk and self.sandbox:
102+
raise ClientConfigurationError("bulk mode is not allowed in sandbox mode")

tests/unit/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def get_client(**kwargs: Any) -> mt.MailtrapClient:
3636
[
3737
{"sandbox": True},
3838
{"inbox_id": "12345"},
39+
{"bulk": True, "sandbox": True, "inbox_id": "12345"},
3940
],
4041
)
4142
def test_client_validation(self, arguments: Dict[str, Any]) -> None:
@@ -59,6 +60,10 @@ def test_base_url_should_truncate_slash_from_host(self) -> None:
5960
{"sandbox": True, "inbox_id": "12345"},
6061
"https://sandbox.api.mailtrap.io:443/api/send/12345",
6162
),
63+
(
64+
{"bulk": True},
65+
"https://bulk.api.mailtrap.io:443/api/send",
66+
),
6267
],
6368
)
6469
def test_api_send_url_should_return_default_sending_url(

0 commit comments

Comments
 (0)