File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313class MailtrapClient :
1414 DEFAULT_HOST = "send.api.mailtrap.io"
1515 DEFAULT_PORT = 443
16+ BULK_HOST = "bulk.api.mailtrap.io"
1617 SANDBOX_HOST = "sandbox.api.mailtrap.io"
1718
1819 def __init__ (
1920 self ,
2021 token : str ,
2122 api_host : Optional [str ] = None ,
2223 api_port : int = DEFAULT_PORT ,
24+ bulk : bool = False ,
2325 sandbox : bool = False ,
2426 inbox_id : Optional [str ] = None ,
2527 ) -> None :
2628 self .token = token
2729 self .api_host = api_host
2830 self .api_port = api_port
31+ self .bulk = bulk
2932 self .sandbox = sandbox
3033 self .inbox_id = inbox_id
3134
@@ -70,6 +73,8 @@ def _host(self) -> str:
7073 return self .api_host
7174 if self .sandbox :
7275 return self .SANDBOX_HOST
76+ if self .bulk :
77+ return self .BULK_HOST
7378 return self .DEFAULT_HOST
7479
7580 @staticmethod
@@ -90,3 +95,6 @@ def _validate_itself(self) -> None:
9095 raise ClientConfigurationError (
9196 "`inbox_id` is not allowed in non-sandbox mode"
9297 )
98+
99+ if self .bulk and self .sandbox :
100+ raise ClientConfigurationError ("bulk mode is not allowed in sandbox mode" )
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ def get_client(**kwargs: Any) -> mt.MailtrapClient:
3535 [
3636 {"sandbox" : True },
3737 {"inbox_id" : "12345" },
38+ {"bulk" : True , "sandbox" : True , "inbox_id" : "12345" },
3839 ],
3940 )
4041 def test_client_validation (self , arguments : dict [str , Any ]) -> None :
@@ -54,10 +55,22 @@ def test_base_url_should_truncate_slash_from_host(self) -> None:
5455 {"api_host" : "example.send.com" , "api_port" : 543 },
5556 "https://example.send.com:543/api/send" ,
5657 ),
58+ (
59+ {"api_host" : "example.send.com" , "sandbox" : True , "inbox_id" : "12345" },
60+ "https://example.send.com:443/api/send/12345" ,
61+ ),
62+ (
63+ {"api_host" : "example.send.com" , "bulk" : True },
64+ "https://example.send.com:443/api/send" ,
65+ ),
5766 (
5867 {"sandbox" : True , "inbox_id" : "12345" },
5968 "https://sandbox.api.mailtrap.io:443/api/send/12345" ,
6069 ),
70+ (
71+ {"bulk" : True },
72+ "https://bulk.api.mailtrap.io:443/api/send" ,
73+ ),
6174 ],
6275 )
6376 def test_api_send_url_should_return_default_sending_url (
You can’t perform that action at this time.
0 commit comments