Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
sudo: false


language: python


branches:
only:
- master


matrix:
fast_finish: true
include:
- python: 3.5
env: TOXENV=py35-django111
- python: 3.5
env: TOXENV=py35-django20
- python: 3.6
env: TOXENV=py36-django111
- python: 3.6
env: TOXENV=py36-django20


before_cache:
- rm -rf $HOME/.cache/pip/log


cache:
directories:
- $HOME/.cache/pip


install:
- pip install tox


script:
- tox
6 changes: 3 additions & 3 deletions django_postmark_utils/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class EmailBackend(EmailBackend):
"""
A wrapper that by default quashes exceptions raised while sending messages.
A wrapper that quashes exceptions raised while sending messages.
"""

def __init__(self, token=None, fail_silently=True, **kwargs):
super().__init__(token=token, fail_silently=fail_silently, **kwargs)
def __init__(self, token=None, fail_silently=False, **kwargs):
super().__init__(token=token, fail_silently=True, **kwargs)
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

test_requires = [
'pytest==3.6.3',
'pytest-django==3.3.2',
'pytest-xdist==1.22.2',
]

setup(
name='django-postmark-utils',
version='0.1',
Expand All @@ -21,6 +27,9 @@
'postmarker>=0.11.3',
'python-dateutil>=2.0',
],
extras_require={
'test': test_requires,
},
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
Expand Down
9 changes: 9 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SECRET_KEY = 'foo'


# Postmarker

EMAIL_BACKEND = 'django_postmark_utils.backends.EmailBackend'
POSTMARK = {
'TOKEN': '<YOUR POSTMARK SERVER TOKEN>',
}
42 changes: 42 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from django.core import mail

from postmarker.exceptions import PostmarkerException


@pytest.fixture
def email_backend(settings):
"""
Overrides the EMAIL_BACKEND setting, because "pytest-django" uses
"django.test.utils.setup_test_environment", where it is set to
"django.core.mail.backends.locmem.EmailBackend".
"""
settings.EMAIL_BACKEND = 'django_postmark_utils.backends.EmailBackend'


@pytest.fixture
def postmark_response(postmark_request):
"""
Mocks an error response from a Postmark API call via Postmarker.
"""
postmark_request.return_value.json.side_effect = PostmarkerException


def send_with_connection(connection):
mail.EmailMessage(
'Subject', 'Body', 'sender@example.com', ['receiver@example.com'],
connection=connection,
).send()


@pytest.mark.usefixtures('email_backend', 'postmark_response')
class TestExceptions:

def test_silent_exception_by_default(self):
with mail.get_connection() as connection:
send_with_connection(connection)

def test_silent_exception_forced(self):
with mail.get_connection(fail_silently=False) as connection:
send_with_connection(connection)
17 changes: 17 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[pytest]
DJANGO_SETTINGS_MODULE = tests.settings


[tox]
envlist =
py{35,36}-django{111,20}


[testenv]
commands = pytest {posargs}
extras = test
deps =
django111: Django>=1.11,<2.0
django20: Django>=2.0,<2.1
setenv =
PYTHONPATH = {toxinidir}