From bad6bc9dc06f8be8a4ec6bfb9262eeebd40db14e Mon Sep 17 00:00:00 2001 From: Alex Kerney Date: Sun, 1 Oct 2017 17:24:42 -0400 Subject: [PATCH] Adding more tests and splitting up requirements --- .travis.yml | 1 - requirements_dev.txt | 10 +++---- requirements_docs.txt | 1 + requirements_test.txt | 5 ++++ tests/test_email_to.py | 61 ++++++++++++++++++++++++++++++++---------- tox.ini | 2 +- 6 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 requirements_docs.txt create mode 100644 requirements_test.txt diff --git a/.travis.yml b/.travis.yml index 10d454a..756184e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,5 +29,4 @@ python: - 3.4 - 3.3 - 2.7 -- 2.6 script: tox diff --git a/requirements_dev.txt b/requirements_dev.txt index 49ef818..bfd685e 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,12 +2,10 @@ pip==8.1.2 bumpversion==0.5.3 wheel==0.29.0 watchdog==0.8.3 -flake8==2.6.0 -tox==2.3.1 -coverage==4.1 Sphinx==1.4.8 -sphinxcontrib-napoleon cryptography==1.7 PyYAML==3.11 -pytest==2.9.2 -pytest-runner==2.11.1 + + +-r requirements_test.txt +-r requirements_docs.txt \ No newline at end of file diff --git a/requirements_docs.txt b/requirements_docs.txt new file mode 100644 index 0000000..806762d --- /dev/null +++ b/requirements_docs.txt @@ -0,0 +1 @@ +sphinxcontrib-napoleon \ No newline at end of file diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..d55dffd --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1,5 @@ +pytest==2.9.2 +pytest-runner==2.11.1 +flake8==2.6.0 +tox==2.3.1 +coverage==4.1 \ No newline at end of file diff --git a/tests/test_email_to.py b/tests/test_email_to.py index a9e561d..1e32c33 100644 --- a/tests/test_email_to.py +++ b/tests/test_email_to.py @@ -6,20 +6,53 @@ import pytest -from email_to import email_to +import email_to @pytest.fixture -def response(): - """Sample pytest fixture. - - See more at: http://doc.pytest.org/en/latest/fixture.html - """ - # import requests - # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') - - -def test_content(response): - """Sample pytest test function with the pytest fixture as an argument.""" - # from bs4 import BeautifulSoup - # assert 'GitHub' in BeautifulSoup(response.content).title.string +def message(): + """ Simple message """ + msg = email_to.Message('# A Test Message', style='h1 { color: blue }') + msg.add('This message is only a test of the alert system') + return msg + + +def test_build_message(message): + """ Test that a message can be created and added to directly """ + msg = message + + msg_string = str(msg) + assert '# A Test Message' in msg_string + assert 'This message is only a test of the alert system' in msg_string + + msg_html = msg.html + assert '' in msg_html + assert '' in msg_html + assert '' in msg_html + assert 'style="color:blue">' in msg_html + assert 'A Test Message' in msg_html + assert '

This message is only a test of the alert system' in msg_html + + +def test_empty_message(): + """ Test that a message passed an empty body gets created """ + msg = email_to.Message() + msg_string = str(msg) + assert msg_string == '' + + msg_html = msg.html + assert msg.html == '' + + +def test_message_mime(message): + """ Test that a message can form a valid MIMEMultiPart object """ + mime = message.mime() + mime_string = str(mime) + assert 'Content-Type' in mime_string + assert 'multipart/alternative' in mime_string + #assert 'From' in mime_string + assert 'MIME-Version:' in mime_string + assert 'Content-Type: text/plain; charset="us-ascii"' in mime_string + assert '# A Test Message' in mime_string + assert 'Content-Type: text/html; charset="us-ascii"' in mime_string + assert '

A Test Message

' in mime_string diff --git a/tox.ini b/tox.ini index 05d66c3..a67165b 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ commands=flake8 email_to setenv = PYTHONPATH = {toxinidir} deps = - -r{toxinidir}/requirements_dev.txt + -r{toxinidir}/requirements_test.txt commands = pip install -U pip py.test --basetemp={envtmpdir}