From 9c40103a3c3dcdb3e4c4edae9f466f1701e022fc Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 7 Jan 2015 12:12:24 -0400 Subject: Complete IMAP implementation, update tests --- src/leap/mail/tests/common.py | 17 +++++------- src/leap/mail/tests/test_mailbox_indexer.py | 41 ++++++++++++++++++----------- 2 files changed, 33 insertions(+), 25 deletions(-) (limited to 'src/leap/mail/tests') diff --git a/src/leap/mail/tests/common.py b/src/leap/mail/tests/common.py index fefa7ee..a411b2d 100644 --- a/src/leap/mail/tests/common.py +++ b/src/leap/mail/tests/common.py @@ -21,6 +21,9 @@ import os import shutil import tempfile +from twisted.internet import defer +from twisted.trial import unittest + from leap.common.testing.basetest import BaseLeapTest from leap.soledad.client import Soledad @@ -60,7 +63,7 @@ def _initialize_soledad(email, gnupg_home, tempdir): return soledad -class SoledadTestMixin(BaseLeapTest): +class SoledadTestMixin(unittest.TestCase, BaseLeapTest): """ It is **VERY** important that this base is added *AFTER* unittest.TestCase """ @@ -68,15 +71,7 @@ class SoledadTestMixin(BaseLeapTest): def setUp(self): self.results = [] - self.old_path = os.environ['PATH'] - self.old_home = os.environ['HOME'] - self.tempdir = tempfile.mkdtemp(prefix="leap_tests-") - self.home = self.tempdir - bin_tdir = os.path.join( - self.tempdir, - 'bin') - os.environ["PATH"] = bin_tdir - os.environ["HOME"] = self.tempdir + self.setUpEnv() # Soledad: config info self.gnupg_home = "%s/gnupg" % self.tempdir @@ -88,6 +83,8 @@ class SoledadTestMixin(BaseLeapTest): self.gnupg_home, self.tempdir) + return defer.succeed(True) + def tearDown(self): """ tearDown method called after each test. diff --git a/src/leap/mail/tests/test_mailbox_indexer.py b/src/leap/mail/tests/test_mailbox_indexer.py index 2edf1d8..b82fd2d 100644 --- a/src/leap/mail/tests/test_mailbox_indexer.py +++ b/src/leap/mail/tests/test_mailbox_indexer.py @@ -84,18 +84,6 @@ class MailboxIndexerTestCase(SoledadTestMixin): d.addCallback(assert_table_deleted) return d - #def test_rename_table(self): - #def assert_table_renamed(tables): - #self.assertEqual( - #tables, ["leapmail_uid_foomailbox"]) -# - #m_uid = self.get_mbox_uid() - #d = m_uid.create_table('inbox') - #d.addCallback(lambda _: m_uid.rename_table('inbox', 'foomailbox')) - #d.addCallback(self.list_mail_tables_cb) - #d.addCallback(assert_table_renamed) - #return d - def test_insert_doc(self): m_uid = self.get_mbox_uid() @@ -168,7 +156,6 @@ class MailboxIndexerTestCase(SoledadTestMixin): def test_get_doc_id_from_uid(self): m_uid = self.get_mbox_uid() - #mbox = 'foomailbox' h1 = fmt_hash(mbox_id, hash_test0) @@ -183,7 +170,6 @@ class MailboxIndexerTestCase(SoledadTestMixin): def test_count(self): m_uid = self.get_mbox_uid() - #mbox = 'foomailbox' h1 = fmt_hash(mbox_id, hash_test0) h2 = fmt_hash(mbox_id, hash_test1) @@ -216,7 +202,6 @@ class MailboxIndexerTestCase(SoledadTestMixin): def test_get_next_uid(self): m_uid = self.get_mbox_uid() - #mbox = 'foomailbox' h1 = fmt_hash(mbox_id, hash_test0) h2 = fmt_hash(mbox_id, hash_test1) @@ -237,3 +222,29 @@ class MailboxIndexerTestCase(SoledadTestMixin): d.addCallback(lambda _: m_uid.get_next_uid(mbox_id)) d.addCallback(partial(assert_next_uid, expected=6)) return d + + def test_all_uid_iter(self): + + m_uid = self.get_mbox_uid() + + h1 = fmt_hash(mbox_id, hash_test0) + h2 = fmt_hash(mbox_id, hash_test1) + h3 = fmt_hash(mbox_id, hash_test2) + h4 = fmt_hash(mbox_id, hash_test3) + h5 = fmt_hash(mbox_id, hash_test4) + + d = m_uid.create_table(mbox_id) + d.addCallback(lambda _: m_uid.insert_doc(mbox_id, h1)) + d.addCallback(lambda _: m_uid.insert_doc(mbox_id, h2)) + d.addCallback(lambda _: m_uid.insert_doc(mbox_id, h3)) + d.addCallback(lambda _: m_uid.insert_doc(mbox_id, h4)) + d.addCallback(lambda _: m_uid.insert_doc(mbox_id, h5)) + d.addCallback(lambda _: m_uid.delete_doc_by_uid(mbox_id, 1)) + d.addCallback(lambda _: m_uid.delete_doc_by_uid(mbox_id, 4)) + + def assert_all_uid(result, expected=[2, 3, 5]): + self.assertEquals(result, expected) + + d.addCallback(lambda _: m_uid.all_uid_iter(mbox_id)) + d.addCallback(partial(assert_all_uid)) + return d -- cgit v1.2.3