4 import mail
, email
.Message
10 mail_from_address
= None
11 mail_to_address
= None
15 # we define our needed mock SMTP
17 def __init__(self
, host
=None, port
=25):
18 test_data
.mail_host
= host
19 test_data
.mail_port
= port
21 if test_data
.mail_host
:
22 self
.connect(test_data
.mail_host
, test_data
.mail_port
)
25 def connect(self
, host
, port
):
26 test_data
.mail_connect
= True
30 test_data
.mail_connect
= False
33 def sendmail(self
, from_address
, to_address
, message
):
34 test_data
.mail_from_address
= from_address
35 test_data
.mail_to_address
= to_address
36 test_data
.mail_message
= message
39 class mail_test(unittest
.TestCase
):
43 # now perform the slip
44 self
.cached_SMTP
= mail
.smtplib
.SMTP
45 mail
.smtplib
.SMTP
= SMTP
50 mail
.smtplib
.SMTP
= self
.cached_SMTP
53 def test_send_message(self
):
54 message
= email
.Message
.Message()
56 message
["Cc"] = "them"
57 message
["From"] = "me"
58 message
["Subject"] = "hello"
59 message
.set_payload("Hello everybody!")
61 mail
.send("me", "you", "them", "hello", "Hello everybody!")
62 self
.assertEquals("me", test_data
.mail_from_address
)
63 self
.assertEquals(["you","them"], test_data
.mail_to_address
)
64 self
.assertEquals(message
.as_string(), test_data
.mail_message
)
67 # this is so the test can be run in standalone mode
68 if __name__
== '__main__':