mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Move tests out of app module
(Directory structure as suggested in [Django testing docs][1].) [1]: https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
This commit is contained in:
47
tests/utils.py
Normal file
47
tests/utils.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Anymail test utils
|
||||
import os
|
||||
import unittest
|
||||
from base64 import b64decode
|
||||
|
||||
import six
|
||||
|
||||
|
||||
def decode_att(att):
|
||||
"""Returns the original data from base64-encoded attachment content"""
|
||||
return b64decode(att.encode('ascii'))
|
||||
|
||||
|
||||
SAMPLE_IMAGE_FILENAME = "sample_image.png"
|
||||
|
||||
|
||||
def sample_image_path(filename=SAMPLE_IMAGE_FILENAME):
|
||||
"""Returns path to an actual image file in the tests directory"""
|
||||
test_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
path = os.path.join(test_dir, filename)
|
||||
return path
|
||||
|
||||
|
||||
def sample_image_content(filename=SAMPLE_IMAGE_FILENAME):
|
||||
"""Returns contents of an actual image file from the tests directory"""
|
||||
filename = sample_image_path(filename)
|
||||
with open(filename, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class AnymailTestMixin:
|
||||
"""Helpful additional methods for Anymail tests"""
|
||||
|
||||
pass
|
||||
# Plus these methods added below:
|
||||
# assertCountEqual
|
||||
# assertRaisesRegex
|
||||
# assertRegex
|
||||
|
||||
# Add the Python 3 TestCase assertions, if they're not already there.
|
||||
# (The six implementations cause infinite recursion if installed on
|
||||
# a py3 TestCase.)
|
||||
for method in ('assertCountEqual', 'assertRaisesRegex', 'assertRegex'):
|
||||
try:
|
||||
getattr(unittest.TestCase, method)
|
||||
except AttributeError:
|
||||
setattr(AnymailTestMixin, method, getattr(six, method))
|
||||
Reference in New Issue
Block a user