[Python-modules-commits] [python-sparkpost] 01/03: Imported Upstream version 1.3.5
Scott Kitterman
kitterman at moszumanska.debian.org
Tue Jun 20 19:20:06 UTC 2017
This is an automated email from the git hooks/post-receive script.
kitterman pushed a commit to branch debian/master
in repository python-sparkpost.
commit 5e09b1d88b1b835217a79c4e7c58c15093afc685
Author: Scott Kitterman <scott at kitterman.com>
Date: Tue Jun 20 15:09:11 2017 -0400
Imported Upstream version 1.3.5
---
CHANGELOG.md | 18 +++++++++++++++--
Makefile | 2 +-
docs/conf.py | 2 +-
examples/base_resource.py | 18 +++++++++++++++++
examples/transmissions/handle_exception.py | 32 ++++++++++++++++++++++++++++++
setup.py | 2 +-
sparkpost/__init__.py | 2 +-
sparkpost/django/message.py | 3 +++
sparkpost/transmissions.py | 18 ++++++++++++++---
test-requirements.txt | 1 +
test/django/test_message.py | 11 ++++++++++
test/test_transmissions.py | 30 ++++++++++++++++++++++++++--
12 files changed, 128 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8ce2a1..83d0ffd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
- [Compare to latest release][unreleased]
+## [1.3.5] - 2017-03-07
+### Added
+- [#141](https://github.com/SparkPost/python-sparkpost/pull/141) Validation for recipients parameter for transmissions
+- [#142](https://github.com/SparkPost/python-sparkpost/pull/142) URI parameter support for transmissions list endpoint. Also added deprecation warning
+
+## [1.3.4] - 2017-02-16
+### Added
+- Examples for exception handling and using the base resource class
+
+### Fixed
+- [#137](https://github.com/SparkPost/python-sparkpost/pull/137) Added missing `campaign` support for Django backend
+
## [1.3.3] - 2017-01-13
### Fixed
- [#135](https://github.com/SparkPost/python-sparkpost/pull/135) Issue where exceptions were not returning properly for some underlying API errors
@@ -116,8 +128,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Metrics class for getting a list of campaigns and domains
- Docs on readthedocs.org
-[unreleased]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.3...HEAD
-[1.3.2]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.2...v1.3.3
+[unreleased]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.5...HEAD
+[1.3.5]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.4...v1.3.5
+[1.3.4]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.3...v1.3.4
+[1.3.3]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.2...v1.3.3
[1.3.2]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.1...v1.3.2
[1.3.1]: https://github.com/sparkpost/python-sparkpost/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/sparkpost/python-sparkpost/compare/v1.2.0...v1.3.0
diff --git a/Makefile b/Makefile
index ac4084e..2725b63 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-.PHONY: analysis all build clean docs docs-install docs-open install release release-test test venv
+.PHONY: analysis all build clean docs docs-install docs-open install release release-test test venv
all: clean venv install
diff --git a/docs/conf.py b/docs/conf.py
index 692e53e..57dc59f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -60,7 +60,7 @@ copyright = u'2014-{year}, Message Systems'.format(year=now.year)
# The short X.Y version.
version = '1.3'
# The full version, including alpha/beta/rc tags.
-release = '1.3.3'
+release = '1.3.5'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/examples/base_resource.py b/examples/base_resource.py
new file mode 100644
index 0000000..307d9ac
--- /dev/null
+++ b/examples/base_resource.py
@@ -0,0 +1,18 @@
+import os
+
+from sparkpost.base import Resource
+
+
+class Webhooks(Resource):
+ key = "webhooks"
+
+ def list(self, **kwargs):
+ results = self.request('GET', self.uri, **kwargs)
+ return results
+
+
+api_key = os.environ.get('SPARKPOST_API_KEY', None)
+webhooks = Webhooks('https://api.sparkpost.com/api/v1', api_key)
+
+# returns a list of webhooks for your account
+print(webhooks.list())
diff --git a/examples/transmissions/handle_exception.py b/examples/transmissions/handle_exception.py
new file mode 100644
index 0000000..558d21c
--- /dev/null
+++ b/examples/transmissions/handle_exception.py
@@ -0,0 +1,32 @@
+"""
+This script demonstrates how to use the SparkPostAPIException class. This
+particular example will yield output similar to the following:
+
+$ python send_transmission_exception.py
+400
+{u'errors': [{u'message': u'Invalid domain', u'code': u'7001', u'description':
+u'Unconfigured Sending Domain <some-domain-you-havent-configured.com> '}]}
+['Invalid domain Code: 7001 Description: Unconfigured Sending Domain
+<some-domain-you-havent-configured.com> \n']
+"""
+
+from sparkpost import SparkPost
+from sparkpost.exceptions import SparkPostAPIException
+
+sp = SparkPost()
+
+try:
+ response = sp.transmissions.send(
+ recipients=['john.doe at example.com'],
+ text='Hello there',
+ from_email='Testing <test at some-domain-you-havent-configured.com>',
+ subject='Testing python-sparkpost exceptions'
+ )
+except SparkPostAPIException as err:
+ # http response status code
+ print(err.status)
+ # python requests library response object
+ # http://docs.python-requests.org/en/master/api/#requests.Response
+ print(err.response.json())
+ # list of formatted errors
+ print(err.errors)
diff --git a/setup.py b/setup.py
index 25b598c..e5886b9 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@ with open('README.rst', 'r', 'utf-8') as f:
setup(
name='sparkpost',
- version='1.3.3',
+ version='1.3.5',
author='SparkPost',
author_email='developers at sparkpost.com',
packages=find_packages(),
diff --git a/sparkpost/__init__.py b/sparkpost/__init__.py
index 96b40f7..c504de9 100644
--- a/sparkpost/__init__.py
+++ b/sparkpost/__init__.py
@@ -9,7 +9,7 @@ from .templates import Templates
from .transmissions import Transmissions
-__version__ = '1.3.3'
+__version__ = '1.3.5'
class SparkPost(object):
diff --git a/sparkpost/django/message.py b/sparkpost/django/message.py
index ee6b225..568fa5a 100644
--- a/sparkpost/django/message.py
+++ b/sparkpost/django/message.py
@@ -87,4 +87,7 @@ class SparkPostMessage(dict):
if hasattr(message, 'substitution_data'):
formatted['substitution_data'] = message.substitution_data
+ if hasattr(message, 'campaign'):
+ formatted['campaign'] = message.campaign
+
super(SparkPostMessage, self).__init__(formatted)
diff --git a/sparkpost/transmissions.py b/sparkpost/transmissions.py
index 3586e2f..dcb7f86 100644
--- a/sparkpost/transmissions.py
+++ b/sparkpost/transmissions.py
@@ -1,9 +1,11 @@
import base64
import copy
import json
+import warnings
from email.utils import parseaddr
from .base import Resource
+from .exceptions import SparkPostException
try:
@@ -137,6 +139,10 @@ class Transmissions(Resource):
return parsed_address
def _extract_recipients(self, recipients):
+
+ if not (isinstance(recipients, (list, dict))):
+ raise SparkPostException('recipients must be a list or dict')
+
formatted_recipients = []
for recip in recipients:
if isinstance(recip, string_types):
@@ -265,15 +271,21 @@ class Transmissions(Resource):
results = self._fetch_get(transmission_id)
return results['transmission']
- def list(self):
+ def list(self, **kwargs):
"""
Get a list of your transmissions
+ :param campaign_id: ID of the campaign used by the transmissions
+ :param template_id: ID of the template used by the transmissions
+
:returns: list of transmissions
:raises: :exc:`SparkPostAPIException` if API call fails
"""
- results = self.request('GET', self.uri)
- return results
+ warn_msg = 'This endpoint is deprecated. For details, '
+ 'check https://sparkpo.st/5qcj4.'
+
+ warnings.warn(warn_msg, DeprecationWarning)
+ return self.request('GET', self.uri, params=kwargs)
def delete(self, transmission_id):
"""
diff --git a/test-requirements.txt b/test-requirements.txt
index 98fd527..6516877 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -3,3 +3,4 @@ pytest==2.8.7
pytest-cov==1.8.1
requests==2.5.1
responses==0.3.0
+mock==2.0.0
diff --git a/test/django/test_message.py b/test/django/test_message.py
index dda735f..08606b8 100644
--- a/test/django/test_message.py
+++ b/test/django/test_message.py
@@ -175,6 +175,17 @@ def test_template():
assert actual == expected
+def test_campaign():
+ email_message = EmailMessage(**base_options)
+ email_message.campaign = 'campaign-id'
+ actual = SparkPostMessage(email_message)
+ expected = dict(
+ campaign='campaign-id'
+ )
+ expected.update(base_expected)
+ assert actual == expected
+
+
def test_substitution_data():
email_message = EmailMessage(
to=[
diff --git a/test/test_transmissions.py b/test/test_transmissions.py
index 9847fb2..c449fe3 100644
--- a/test/test_transmissions.py
+++ b/test/test_transmissions.py
@@ -2,14 +2,16 @@ import base64
import json
import os
import tempfile
+import warnings
import pytest
import responses
import six
+from mock import patch
from sparkpost import SparkPost
from sparkpost import Transmissions
-from sparkpost.exceptions import SparkPostAPIException
+from sparkpost.exceptions import SparkPostAPIException, SparkPostException
def test_translate_keys_with_list():
@@ -29,6 +31,12 @@ def test_translate_keys_with_recips():
{'address': {'email': 'foobar'}}]
+def test_exceptions_for_recipients():
+ t = Transmissions('uri', 'key')
+ with pytest.raises(SparkPostException):
+ t._translate_keys(recipients='test')
+
+
def test_translate_keys_with_unicode_recips():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=[u'unicode_email at example.com',
@@ -297,7 +305,8 @@ def test_fail_get():
@responses.activate
-def test_success_list():
+ at patch.object(warnings, 'warn')
+def test_success_list(mock_warn):
responses.add(
responses.GET,
'https://api.sparkpost.com/api/v1/transmissions',
@@ -307,6 +316,23 @@ def test_success_list():
)
sp = SparkPost('fake-key')
response = sp.transmission.list()
+ assert mock_warn.called
+ assert response == []
+
+
+ at responses.activate
+def test_success_list_with_params():
+ responses.add(
+ responses.GET,
+ 'https://api.sparkpost.com/api/v1/transmissions?template_id=abcd',
+ status=200,
+ content_type='application/json',
+ body='{"results": []}',
+ match_querystring=True
+
+ )
+ sp = SparkPost('fake-key')
+ response = sp.transmission.list(template_id='abcd')
assert response == []
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-sparkpost.git
More information about the Python-modules-commits
mailing list