From 7593213cb2b4a9cca08ecb228c0b36b9a7c3805a Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Tue, 21 Apr 2015 11:30:16 +0200 Subject: Added load-mails maintenance command. - Issue #335 --- service/test/unit/maintenance/test_commands.py | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'service/test/unit/maintenance') diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py index a20b0383..f23655d8 100644 --- a/service/test/unit/maintenance/test_commands.py +++ b/service/test/unit/maintenance/test_commands.py @@ -14,12 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . import unittest +import email -from pixelated.maintenance import delete_all_mails +from pixelated.maintenance import delete_all_mails, load_mails from pixelated.bitmask_libraries.session import LeapSession +from leap.mail.imap.account import SoledadBackedAccount from leap.soledad.client import Soledad from leap.soledad.common.document import SoledadDocument -from mock import MagicMock +from mock import MagicMock, ANY +from os.path import join, dirname class TestCommands(unittest.TestCase): @@ -27,6 +30,11 @@ class TestCommands(unittest.TestCase): def setUp(self): self.leap_session = MagicMock(spec=LeapSession) self.soledad = MagicMock(spec=Soledad) + self.account = MagicMock(spec=SoledadBackedAccount) + self.mailbox = MagicMock() + self.leap_session.account = self.account + self.account.getMailbox.return_value = self.mailbox + self.args = (self.leap_session, self.soledad) def test_delete_all_mails_supports_empty_doclist(self): @@ -63,3 +71,22 @@ class TestCommands(unittest.TestCase): doc = MagicMock(spec=SoledadDocument) doc.content = {'type': doc_type} return doc + + def test_load_mails_empty_path_list(self): + load_mails(self.args, []) + + self.assertFalse(self.mailbox.called) + + def test_load_mails_adds_mails(self): + mail_root = join(dirname(__file__), '..', 'fixtures', 'mailset') + + foo = load_mails(self.args, [mail_root]) + + self.assertTrue(self.mailbox.addMessage.called) + self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'mbox00000000')), flags=("\\RECENT",), notify_on_disk=False) + self.mailbox.addMessage.assert_any_call(self._mail_content(join(mail_root, 'mbox00000001')), flags=("\\RECENT",), notify_on_disk=False) + + def _mail_content(self, mail_file): + with open(mail_file, 'r') as fp: + m = email.message_from_file(fp) + return m.as_string() -- cgit v1.2.3