From b1c997be1d7d7d456cad06ef436c01527e04df5d Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sun, 11 Jul 2010 22:01:51 -0400 Subject: Reworked the Gmail notification plugin to use stanza objects and expose more information. --- tests/test_gmail.py | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/test_gmail.py (limited to 'tests/test_gmail.py') diff --git a/tests/test_gmail.py b/tests/test_gmail.py new file mode 100644 index 00000000..199b76ae --- /dev/null +++ b/tests/test_gmail.py @@ -0,0 +1,88 @@ +from sleektest import * +import sleekxmpp.plugins.gmail_notify as gmail + + +class TestGmail(SleekTest): + + def setUp(self): + self.stanzaPlugin(Iq, gmail.GmailQuery) + self.stanzaPlugin(Iq, gmail.MailBox) + self.stanzaPlugin(Iq, gmail.NewMail) + + def testCreateQuery(self): + """Testing querying Gmail for emails.""" + + iq = self.Iq() + iq['type'] = 'get' + iq['gmail']['search'] = 'is:starred' + iq['gmail']['newer-than-time'] = '1140638252542' + iq['gmail']['newer-than-tid'] = '11134623426430234' + + self.checkIq(iq, """ + + + + """) + + def testMailBox(self): + """Testing reading from Gmail mailbox result""" + + # Use the example from Google's documentation at + # http://code.google.com/apis/talk/jep_extensions/gmail.html#notifications + xml = ET.fromstring(""" + + + + + + + + + act1scene3 + Put thy rapier up. + Ay, ay, a scratch, a scratch; marry, 'tis enough. + + + + """) + + iq = self.Iq(xml=xml) + mailbox = iq['mailbox'] + self.failUnless(mailbox['result-time'] == '1118012394209', "result-time doesn't match") + self.failUnless(mailbox['url'] == 'http://mail.google.com/mail', "url doesn't match") + self.failUnless(mailbox['matched'] == '95', "total-matched incorrect") + self.failUnless(mailbox['estimate'] == False, "total-estimate incorrect") + self.failUnless(len(mailbox['threads']) == 1, "could not extract message threads") + + thread = mailbox['threads'][0] + self.failUnless(thread['tid'] == '1172320964060972012', "thread tid doesn't match") + self.failUnless(thread['participation'] == '1', "thread participation incorrect") + self.failUnless(thread['messages'] == '28', "thread message count incorrect") + self.failUnless(thread['date'] == '1118012394209', "thread date doesn't match") + self.failUnless(thread['url'] == 'http://mail.google.com/mail?view=cv', "thread url doesn't match") + self.failUnless(thread['labels'] == 'act1scene3', "thread labels incorrect") + self.failUnless(thread['subject'] == 'Put thy rapier up.', "thread subject doesn't match") + self.failUnless(thread['snippet'] == "Ay, ay, a scratch, a scratch; marry, 'tis enough.", "snippet doesn't match") + self.failUnless(len(thread['senders']) == 3, "could not extract senders") + + sender1 = thread['senders'][0] + self.failUnless(sender1['name'] == 'Me', "sender name doesn't match") + self.failUnless(sender1['address'] == 'romeo@gmail.com', "sender address doesn't match") + self.failUnless(sender1['originator'] == True, "sender originator incorrect") + self.failUnless(sender1['unread'] == False, "sender unread incorrectly True") + + sender2 = thread['senders'][2] + self.failUnless(sender2['unread'] == True, "sender unread incorrectly False") + +suite = unittest.TestLoader().loadTestsFromTestCase(TestGmail) -- cgit v1.2.3 From d5e42ac0e7282500583bf17f21eb2f944600ce76 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 19 Jul 2010 13:58:53 -0400 Subject: Condensed all of the stanzaPlugin functions into a single registerStanzaPlugin function. Updated plugins and tests to use new function. --- tests/test_gmail.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test_gmail.py') diff --git a/tests/test_gmail.py b/tests/test_gmail.py index 199b76ae..b2e70d21 100644 --- a/tests/test_gmail.py +++ b/tests/test_gmail.py @@ -5,9 +5,9 @@ import sleekxmpp.plugins.gmail_notify as gmail class TestGmail(SleekTest): def setUp(self): - self.stanzaPlugin(Iq, gmail.GmailQuery) - self.stanzaPlugin(Iq, gmail.MailBox) - self.stanzaPlugin(Iq, gmail.NewMail) + registerStanzaPlugin(Iq, gmail.GmailQuery) + registerStanzaPlugin(Iq, gmail.MailBox) + registerStanzaPlugin(Iq, gmail.NewMail) def testCreateQuery(self): """Testing querying Gmail for emails.""" -- cgit v1.2.3 From 58f77d898f82ab108fa17d562a32c68d3ea35306 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 5 Aug 2010 20:23:07 -0400 Subject: Updated tests to use a relative import for SleekTest to please Python3. Fixed some tabs/spaces issues. --- tests/test_gmail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_gmail.py') diff --git a/tests/test_gmail.py b/tests/test_gmail.py index b2e70d21..dd256e27 100644 --- a/tests/test_gmail.py +++ b/tests/test_gmail.py @@ -1,4 +1,4 @@ -from sleektest import * +from . sleektest import * import sleekxmpp.plugins.gmail_notify as gmail -- cgit v1.2.3