This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
testlibgmail.py
93 lines (82 loc) · 2.86 KB
/
testlibgmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
"""
libgmail test suite
Tests:
Very little, at this point :)
"""
import unittest
import time
from libgmail import *
import getpass
class LibgmailTests(unittest.TestCase):
"""
Set of tests that exercise very basic libgmail functionality
"""
def setUp(self):
pass
def tearDown(self):
pass
def test_utf8(self):
f = account.getMessagesByFolder(U_INBOX_SEARCH, True)
for t in f:
for m in t:
w = m.source
for attach in m.attachments:
a = attach.content
def test_send_and_receive_mail(self):
if account.domain:
name = account.name + '@' + account.domain
else:
name = account.name + '@gmail.com'
subject = "libgmail test subject"
body = """
Hi, I am a unit test of libgmail. Ignore this message,
if you dare. Seriously, I won't be offended if you
ignore it. And you probably should, since right
now, the test suite doesn't delete this message
from your trash, sooo.... it'll just linger.
"You've got me wrapped around your finger /
did you have to let it linger?
did you have to?
did you have to?
did you have to let it linger?"
etc.
"""
msg = GmailComposedMessage(to=name, subject=subject,
body=body)
output = account.sendMessage(msg)
# Now go to the inbox and attempt to retrieve
# this message
# Sleep for like, ten seconds, so that we can
# actually get the message
time.sleep(10)
result = account.getMessagesByFolder(U_INBOX_SEARCH)
# We'd better be in the first thread
thread = result[0]
first = thread[0]
self.assertEqual(first.subject, first.subject)
self.assertEqual(first.to[0], msg.to)
# Now send the message to the trash
account.trashMessage(first)
if __name__ == '__main__':
#unittest.main()
## With this we get a better output
print "\n=============================================="
print "Start 'libgmail' testsuite"
print "------------------------------------------------\n"
print "WARNING: THIS TEST MAY DELETE/REARRANGE"
print " YOUR ADDRESSBOOK/EMAILS"
print "PLEASE DON'T RUN IT ON A REAL ACCOUNT"
name = raw_input("Gmail account name: ")
pw = getpass.getpass("Password: ")
domain = raw_input("Domain [leave blank for gmail]: ")
account = GmailAccount(name, pw, domain=domain)
try:
account.login()
print "Login successful.\n"
except GmailLoginFailure,e:
print "\nLogin failed. (%s)" % e.message
else:
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(LibgmailTests))
unittest.TextTestRunner(verbosity=2).run(suite)