Skip to content
Browse files

tests for get_messages_in_mailbox

  • Loading branch information...
1 parent 9074104 commit 32604151dae1ccc4084d2ebabf96428b69d6f183 @mgax mgax committed Jun 2, 2010
Showing with 52 additions and 0 deletions.
  1. +52 −0 src/tinymail/maildata/tests/test_imap.py
View
52 src/tinymail/maildata/tests/test_imap.py
@@ -32,3 +32,55 @@ def list(self):
server = TestServer(StubImapConnection())
self.assertRaises(AssertionError, server.get_mailboxes)
+
+class GetMessagesInMailbox(unittest.TestCase):
+ def test_simple(self):
+ called = []
+ class StubImapConnection(object):
+ def select(self, mailbox, readonly):
+ assert readonly is True
+ assert mailbox == 'testfolder'
+ called.append('select')
+ return 'OK', []
+
+ def search(self, *args):
+ called.append('search')
+ return 'OK', ['1 2']
+
+ def fetch(self, msg_ids, spec):
+ assert msg_ids == '1,2'
+ called.append('fetch')
+ return 'OK', [
+ ('1 (FLAGS (\\Seen) BODY[HEADER] {60}',
+ 'From: somebody@example.com\r\n'
+ 'To: somebody_else@example.com\r\n\r\n'),
+ ')',
+ ('2 (FLAGS (\\Answered \\Seen) BODY[HEADER] {28}',
+ 'Content-Type: text/plain\r\n\r\n'),
+ ')',
+ ]
+
+ server = TestServer(StubImapConnection())
+ out = list(server.get_messages_in_mailbox('testfolder'))
+ self.assertEqual(len(out), 2)
+ self.assertEqual([o[0] for o in out], ['1', '2'])
+ self.assertTrue('From: somebody@example.com' in out[0][1])
+ self.assertTrue('Content-Type: text/plain' in out[1][1])
+
+ self.assertEqual(called, ['select', 'search', 'fetch'])
+
+ def test_empty_folder(self):
+ called = []
+ class StubImapConnection(object):
+ def select(self, mailbox, readonly):
+ called.append('select')
+ return 'OK', []
+
+ def search(self, *args):
+ called.append('search')
+ return 'OK', ['']
+
+ server = TestServer(StubImapConnection())
+ out = list(server.get_messages_in_mailbox('testfolder'))
+ self.assertEqual(out, [])
+ self.assertEqual(called, ['select', 'search'])

0 comments on commit 3260415

Please sign in to comment.
Something went wrong with that request. Please try again.