From 2bf0ad92686c27e5c2ca8f30a3d1ef746c13678e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Wed, 13 Apr 2016 14:00:33 +0100 Subject: [PATCH 1/3] test emails with alternative text and html --- gluon/tests/test_tools.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gluon/tests/test_tools.py b/gluon/tests/test_tools.py index f7173ca0..62433d7f 100644 --- a/gluon/tests/test_tools.py +++ b/gluon/tests/test_tools.py @@ -36,10 +36,19 @@ class TestMail(unittest.TestCase): """ class Message(object): + def __init__(self, sender, to, payload): self.sender = sender self.to = to self.payload = payload + self._parsed_payload = None + + @property + def parsed_payload(self): + if self._parsed_payload is None: + import email + self._parsed_payload = email.message_from_string(self.payload) + return self._parsed_payload class DummySMTP(object): """ @@ -125,6 +134,19 @@ class TestMail(unittest.TestCase): del TestMail.DummySMTP.users['username'] TestMail.DummySMTP.inbox.pop() + def test_alternative(self): + mail = Mail() + mail.settings.server = 'smtp.example.com:25' + mail.settings.sender = 'you@example.com' + self.assertTrue(mail.send(to=['somebody@example.com'], + message=('Text only', '
HTML Only
'))) + message = TestMail.DummySMTP.inbox.pop() + self.assertTrue(message.parsed_payload.is_multipart()) + self.assertTrue(message.parsed_payload.get_content_type() == 'multipart/alternative') + parts = message.parsed_payload.get_payload() + self.assertTrue('Text only' in parts[0].as_string()) + self.assertTrue('
HTML Only
' in parts[1].as_string()) + def test_html(self): mail = Mail() mail.settings.server = 'smtp.example.com:25' @@ -171,9 +193,7 @@ class TestMail(unittest.TestCase): message='world', attachments=Mail.Attachment(module_file))) message = TestMail.DummySMTP.inbox.pop() - import email - parsed_msg = email.message_from_string(message.payload) - attachment = parsed_msg.get_payload(1).get_payload(decode=True) + attachment = message.parsed_payload.get_payload(1).get_payload(decode=True) with open(module_file, 'rb') as mf: self.assertEqual(attachment.decode('utf-8'), mf.read().decode('utf-8')) # Test missing attachment name error From 02a0d1c9b00cafc67d708d10aaf44e2cf05fc80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Wed, 13 Apr 2016 14:01:36 +0100 Subject: [PATCH 2/3] minor reorder --- gluon/tests/test_tools.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gluon/tests/test_tools.py b/gluon/tests/test_tools.py index 62433d7f..53800e7b 100644 --- a/gluon/tests/test_tools.py +++ b/gluon/tests/test_tools.py @@ -134,6 +134,18 @@ class TestMail(unittest.TestCase): del TestMail.DummySMTP.users['username'] TestMail.DummySMTP.inbox.pop() + def test_html(self): + mail = Mail() + mail.settings.server = 'smtp.example.com:25' + mail.settings.sender = 'you@example.com' + self.assertTrue(mail.send(to=['somebody@example.com'], + subject='hello', + # If reply_to is omitted, then mail.settings.sender is used + reply_to='us@example.com', + message='')) + message = TestMail.DummySMTP.inbox.pop() + self.assertTrue('Content-Type: text/html' in message.payload) + def test_alternative(self): mail = Mail() mail.settings.server = 'smtp.example.com:25' @@ -147,18 +159,6 @@ class TestMail(unittest.TestCase): self.assertTrue('Text only' in parts[0].as_string()) self.assertTrue('
HTML Only
' in parts[1].as_string()) - def test_html(self): - mail = Mail() - mail.settings.server = 'smtp.example.com:25' - mail.settings.sender = 'you@example.com' - self.assertTrue(mail.send(to=['somebody@example.com'], - subject='hello', - # If reply_to is omitted, then mail.settings.sender is used - reply_to='us@example.com', - message='')) - message = TestMail.DummySMTP.inbox.pop() - self.assertTrue('Content-Type: text/html' in message.payload) - def test_ssl(self): mail = Mail() mail.settings.server = 'smtp.example.com:25' From 4bbfe7092768773a5fc2bd938084880783a8db5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Wed, 13 Apr 2016 14:17:30 +0100 Subject: [PATCH 3/3] install a more modern pypy version --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.travis.yml b/.travis.yml index bcc9ba01..a785e983 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,22 @@ python: - 'pypy' install: + - | + if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then + export PYENV_ROOT="$HOME/.pyenv" + if [ -f "$PYENV_ROOT/bin/pyenv" ]; then + pushd "$PYENV_ROOT" && git pull && popd + else + rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT" + fi + export PYPY_VERSION="5.0.1" + "$PYENV_ROOT/bin/pyenv" install --skip-existing "pypy-$PYPY_VERSION" + virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION" + source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" + fi - pip install -e . + before_script: - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install --download-cache $HOME/.pip-cache unittest2; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache coverage; fi;