diff options
author | Joar Wandborg <git@wandborg.com> | 2011-05-04 22:31:08 +0200 |
---|---|---|
committer | Joar Wandborg <git@wandborg.com> | 2011-05-04 22:31:08 +0200 |
commit | eee2c3a7e699da493ed9b5c11d0c5873441a7abb (patch) | |
tree | 2f4c318d1a2e20f38a2ac8e4458ed30c7c82c217 /mediagoblin/tests/test_util.py | |
parent | 7b3fcddbf4fd6418aceb9e0d06b912a0d79c4a97 (diff) | |
parent | 61ec968b0d1a3681bbc049d651f67100b64e1f6d (diff) | |
download | mediagoblin-eee2c3a7e699da493ed9b5c11d0c5873441a7abb.tar.lz mediagoblin-eee2c3a7e699da493ed9b5c11d0c5873441a7abb.tar.xz mediagoblin-eee2c3a7e699da493ed9b5c11d0c5873441a7abb.zip |
Merge branch 'master' of http://git.gitorious.org/mediagoblin/mediagoblin
Diffstat (limited to 'mediagoblin/tests/test_util.py')
-rw-r--r-- | mediagoblin/tests/test_util.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py index 0e7a2967..5bc31fd6 100644 --- a/mediagoblin/tests/test_util.py +++ b/mediagoblin/tests/test_util.py @@ -14,9 +14,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import email + from mediagoblin import util +util._activate_testing() + + def _import_component_testing_method(silly_string): # Just for the sake of testing that our component importer works. return u"'%s' is the silliest string I've ever seen" % silly_string @@ -28,3 +33,39 @@ def test_import_component(): result = imported_func('hooobaladoobala') expected = u"'hooobaladoobala' is the silliest string I've ever seen" assert result == expected + + +def test_send_email(): + util._clear_test_inboxes() + + # send the email + util.send_email( + "sender@mediagoblin.example.org", + ["amanda@example.org", "akila@example.org"], + "Testing is so much fun!", + """HAYYY GUYS! + +I hope you like unit tests JUST AS MUCH AS I DO!""") + + # check the main inbox + assert len(util.EMAIL_TEST_INBOX) == 1 + message = util.EMAIL_TEST_INBOX.pop() + assert message['From'] == "sender@mediagoblin.example.org" + assert message['To'] == "amanda@example.org, akila@example.org" + assert message['Subject'] == "Testing is so much fun!" + assert message.get_payload(decode=True) == """HAYYY GUYS! + +I hope you like unit tests JUST AS MUCH AS I DO!""" + + # Check everything that the FakeMhost.sendmail() method got is correct + assert len(util.EMAIL_TEST_MBOX_INBOX) == 1 + mbox_dict = util.EMAIL_TEST_MBOX_INBOX.pop() + assert mbox_dict['from'] == "sender@mediagoblin.example.org" + assert mbox_dict['to'] == ["amanda@example.org", "akila@example.org"] + mbox_message = email.message_from_string(mbox_dict['message']) + assert mbox_message['From'] == "sender@mediagoblin.example.org" + assert mbox_message['To'] == "amanda@example.org, akila@example.org" + assert mbox_message['Subject'] == "Testing is so much fun!" + assert mbox_message.get_payload(decode=True) == """HAYYY GUYS! + +I hope you like unit tests JUST AS MUCH AS I DO!""" |