Added unit test for email
This commit is contained in:
@@ -19,6 +19,7 @@ import logging
|
|||||||
SETTINGS = "settings.cfg"
|
SETTINGS = "settings.cfg"
|
||||||
EMAIL_SETTINGS = "EmailSettings.cfg"
|
EMAIL_SETTINGS = "EmailSettings.cfg"
|
||||||
|
|
||||||
|
|
||||||
def showhelp():
|
def showhelp():
|
||||||
"""
|
"""
|
||||||
Prints the command lines switches that are valid for the program.
|
Prints the command lines switches that are valid for the program.
|
||||||
@@ -154,7 +155,7 @@ def main(argv):
|
|||||||
generallogger.info("==========================="
|
generallogger.info("==========================="
|
||||||
"=============\n\n")
|
"=============\n\n")
|
||||||
|
|
||||||
libemail.SendEmail(EMAIL_SETTINGS, "Encoding Complete",
|
libemail.sendemail(EMAIL_SETTINGS, "Encoding Complete",
|
||||||
"Finished encoding {0} shows."
|
"Finished encoding {0} shows."
|
||||||
.format(len(showdata)))
|
.format(len(showdata)))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import smtplib
|
|||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
|
|
||||||
def SendEmail(settingsfilename, subject, body):
|
def sendemail(settingsfilename, subject, body):
|
||||||
settings = EmailSettings(settingsfilename)
|
settings = EmailSettings(settingsfilename)
|
||||||
|
|
||||||
msg = MIMEText(body, "plain")
|
msg = MIMEText(body, "plain")
|
||||||
|
|||||||
@@ -299,4 +299,4 @@ class EmailSettings:
|
|||||||
Get the to address for emails
|
Get the to address for emails
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.__config["To"]
|
return self.__config["To"]
|
||||||
|
|||||||
@@ -5,3 +5,34 @@ Created on Fri Jul 19 23:31:16 2013
|
|||||||
@author: shanef
|
@author: shanef
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from minimock import Mock, mock
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, parentdir)
|
||||||
|
import libemail
|
||||||
|
#from libsettings import EmailSettings
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
|
||||||
|
class libemailtest(unittest.TestCase):
|
||||||
|
def test_SendEmail(self):
|
||||||
|
#EmailSettings = Mock('libsettings.EmailSettings')
|
||||||
|
#libsettings.EmailSettings.mock_returns = Mock('emailsettings')
|
||||||
|
|
||||||
|
#EmailSettings.getfromaddress.mock_returns = "from@email.com"
|
||||||
|
#libsettings.EmailSettings.gettoaddress.mock_returns = "to@gmail.com"
|
||||||
|
mock("EmailSettings.getfromaddress", returns="from@email.com")
|
||||||
|
mock("EmailSettings.gettoaddress", returns="to@email.com")
|
||||||
|
mock("EmailSettings.getsmtpserver", returns="smtp.test")
|
||||||
|
mock("EmailSettings.getsmtpuser", returns="user")
|
||||||
|
mock("EmailSettings.getsmtppassword", returns="password")
|
||||||
|
smtplib.SMTP = Mock('smtplib.SMTP')
|
||||||
|
smtplib.SMTP.mock_returns = Mock('smtp_connection')
|
||||||
|
|
||||||
|
libemail.sendemail("test", "subject", "body")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
suite = unittest.TestLoader().loadTestsFromTestCase(libemailtest)
|
||||||
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||||
|
|||||||
Reference in New Issue
Block a user