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:
medmunds
2016-03-21 11:38:58 -07:00
parent bb8494263f
commit 385d76b53a
17 changed files with 2 additions and 3 deletions

47
tests/utils.py Normal file
View 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))