Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
add unit test to test mail box
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Apr 17, 2016
1 parent 3deeecf commit 7c0cdbf
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 17 deletions.
83 changes: 83 additions & 0 deletions _unittests/ut_grabber/test_mailbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
"""
@brief test log(time=1s)
"""

import sys
import os
import unittest

try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_


from src.pymmails import MailBoxImap, EmailMessageRenderer
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder


class TestMailBox(unittest.TestCase):

def test_mailbox(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

code = "voju/uftu/1/teqzuipo%"
code = "".join(chr(ord(_) - 1) for _ in code)
box = MailBoxImap("unittest.sdpython", code,
"imap.gmail.com", ssl=True, fLOG=fLOG)
box.login()
mails = box.enumerate_mails_in_folder("test4", date="1-Jan-2016")
li = list(mails)
self.assertEqual(len(li), 3)
box.logout()

def test_mailbox_dump(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

temp = get_temp_folder(__file__, "temp_dump")
code = "voju/uftu/1/teqzuipo%"
code = "".join(chr(ord(_) - 1) for _ in code)
box = MailBoxImap("unittest.sdpython", code,
"imap.gmail.com", ssl=True, fLOG=fLOG)
render = EmailMessageRenderer()
box.login()
mails = box.enumerate_mails_in_folder("test4", date="1-Jan-2016")
for mail in mails:
mail.dump(render, location=temp, fLOG=fLOG)
render.flush()
box.logout()

if __name__ == "__main__":
unittest.main()
21 changes: 4 additions & 17 deletions src/pymmails/sender/email_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
COMMASPACE = ', '


def compose_email(
fr,
to,
subject,
body=None,
attachements=None):
def compose_email(fr, to, subject, body=None, attachements=None):
"""
compose an email as a string
Expand Down Expand Up @@ -109,11 +104,7 @@ def create_smtp_server(host, username, password):
return server


def send_email(server, fr,
to,
subject,
body=None,
attachements=None):
def send_email(server, fr, to, subject, body=None, attachements=None):
"""
compose an email as a string
Expand Down Expand Up @@ -144,10 +135,6 @@ def send_email(server, fr,
explains how to enable that option.
@endFAQ
"""
astring = compose_email(
fr,
to,
subject,
body=body,
attachements=attachements)
astring = compose_email(fr, to, subject, body=body,
attachements=attachements)
server.sendmail(fr, to, astring)

0 comments on commit 7c0cdbf

Please sign in to comment.