-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for batchWithTemplates
Fixes #156
- Loading branch information
1 parent
f46d0eb
commit 33bf3b6
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,11 +87,23 @@ def email(postmark): | |
return postmark.emails.Email(From="[email protected]", To="[email protected]", TextBody="text") | ||
|
||
|
||
@pytest.fixture() | ||
def email_template(postmark): | ||
return postmark.emails.EmailTemplate( | ||
From="[email protected]", To="[email protected]", TemplateId=983381, TemplateModel={} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def email_batch(postmark, email): | ||
return postmark.emails.EmailBatch(email) | ||
|
||
|
||
@pytest.fixture | ||
def email_template_batch(postmark, email): | ||
return postmark.emails.EmailTemplateBatch(email) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def template(postmark): | ||
return postmark.templates.get(983381) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,3 +377,45 @@ def test_inline_image(self, email, postmark_request, image, expected): | |
class TestDelivery: | ||
def test_str(self, delivery_webhook): | ||
assert str(delivery_webhook) == "Delivery to [email protected]" | ||
|
||
|
||
class TestTemplateBatchSend: | ||
def test_template_email_instance(self, postmark, email_template, postmark_request): | ||
postmark.emails.send_template_batch(email_template) | ||
assert postmark_request.call_args[1]["json"] == {"Messages": (email_template.as_dict(),)} | ||
|
||
def test_dict(self, postmark, postmark_request): | ||
template_dict = { | ||
"TemplateId": 983381, | ||
"TemplateModel": {}, | ||
"From": "[email protected]", | ||
"To": "[email protected]", | ||
} | ||
expected = { | ||
"TemplateId": 983381, | ||
"TemplateModel": {}, | ||
"From": "[email protected]", | ||
"To": "[email protected]", | ||
"Headers": [], | ||
"Attachments": [], | ||
} | ||
postmark.emails.send_template_batch(template_dict) | ||
assert postmark_request.call_args[1]["json"] == {"Messages": (expected,)} | ||
|
||
def test_multiple(self, postmark, email_template, postmark_request): | ||
postmark.emails.send_template_batch(email_template, email_template) | ||
assert postmark_request.call_args[1]["json"] == { | ||
"Messages": ( | ||
email_template.as_dict(), | ||
email_template.as_dict(), | ||
) | ||
} | ||
|
||
def test_invalid(self, postmark): | ||
with pytest.raises(ValueError): | ||
postmark.emails.send_template_batch(object()) | ||
|
||
|
||
class TestEmailTemplateBatch: | ||
def test_len(self, email_template_batch): | ||
assert len(email_template_batch) == 1 |