Skip to content

Commit

Permalink
Merge pull request #191 from Stranger6667/dd/template-alias-fix
Browse files Browse the repository at this point in the history
fix: Make `TemplateID` not required if `TemplateAlias` is specified
  • Loading branch information
Stranger6667 authored Dec 22, 2020
2 parents c42f1e3 + 78fc83c commit 830462f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python: [3.5, 3.6, 3.7, 3.8, 3.9.0-rc.1, pypy3]
python: [3.6, 3.7, 3.8, 3.9.0-rc.1, pypy3]
exclude:
# pytest bug on PyPy3
# https://github.com/Stranger6667/postmarker/pull/187/checks?check_run_id=1046220597
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Or you can look at the docs/ directory in the repository.
Python support
==============

Postmarker supports Python 3.5 - 3.9 and PyPy3.
Postmarker supports Python 3.6 - 3.9 and PyPy3.

Thanks
======
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Changelog
`Unreleased`_
-------------

Fixed
~~~~~

- Make ``TemplateID`` not required if ``TemplateAlias`` is specified. `#179`_

Removed
~~~~~~~

- Support for Python 3.5.

`0.16.0`_ - 2020-11-10
----------------------

Expand Down Expand Up @@ -422,6 +432,7 @@ Fixed
.. _#184: https://github.com/Stranger6667/postmarker/pull/184
.. _#183: https://github.com/Stranger6667/postmarker/pull/183
.. _#181: https://github.com/Stranger6667/postmarker/pull/181
.. _#179: https://github.com/Stranger6667/postmarker/issues/179
.. _#170: https://github.com/Stranger6667/postmarker/issues/170
.. _#168: https://github.com/Stranger6667/postmarker/issues/168
.. _#163: https://github.com/Stranger6667/postmarker/issues/163
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand Down
11 changes: 9 additions & 2 deletions src/postmarker/models/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ def send(self):


class EmailTemplate(BaseEmail):
def __init__(self, **kwargs):
if kwargs.get("TemplateId") is None and kwargs.get("TemplateAlias") is None:
raise ValueError("You need to specify either TemplateId or TemplateAlias")
super().__init__(**kwargs)

def send(self):
return self._manager._send_with_template(**self.as_dict())

Expand Down Expand Up @@ -352,7 +357,8 @@ def send(

def send_with_template(
self,
TemplateId,
*,
TemplateId=None,
TemplateModel,
From,
To,
Expand Down Expand Up @@ -443,7 +449,8 @@ def Email(

def EmailTemplate(
self,
TemplateId,
*,
TemplateId=None,
TemplateModel,
From,
To,
Expand Down
18 changes: 18 additions & 0 deletions test/models/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ def test_send_with_template(self, postmark):
"To": "receiver@example.com",
}

def test_template_with_alias_only(self, postmark):
# It should be possible to specify `TemplateAlias` and not `TemplateId`
postmark.emails.EmailTemplate(
TemplateAlias="foo",
TemplateModel={},
From="sender@example.com",
To="receiver@example.com",
)

def test_send_with_template_without_alias_and_id(self, postmark):
# If there is no `TemplateAlias` and `TemplateId` then it is an error
with pytest.raises(ValueError):
postmark.emails.send_with_template(
TemplateModel={},
From="sender@example.com",
To="receiver@example.com",
)


class TestBatchSend:
def test_email_instance(self, postmark, email, postmark_request):
Expand Down

0 comments on commit 830462f

Please sign in to comment.