virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / client / common_lib / mail_unittest.py
blobcac7ee6d0e02fef88083c8da3dd42e2f7dc2d826
1 #!/usr/bin/python
3 import unittest
4 import mail, email.Message
6 class test_data:
7 mail_host = None
8 mail_port = None
9 mail_connect = False
10 mail_from_address = None
11 mail_to_address = None
12 mail_message = None
15 # we define our needed mock SMTP
16 class 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
29 def quit(self):
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):
40 cached_SMTP = None
42 def setUp(self):
43 # now perform the slip
44 self.cached_SMTP = mail.smtplib.SMTP
45 mail.smtplib.SMTP = SMTP
48 def tearDown(self):
49 # now put things back
50 mail.smtplib.SMTP = self.cached_SMTP
53 def test_send_message(self):
54 message = email.Message.Message()
55 message["To"] = "you"
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__':
69 unittest.main()