2012-01-09 13:12:28 +01:00
|
|
|
# Copyright (C) 2012- Sebastian Spaeth & contributors
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
import unittest
|
|
|
|
import logging
|
2012-01-18 22:41:05 +01:00
|
|
|
from test.OLItest import OLITestLib
|
2012-01-09 13:12:28 +01:00
|
|
|
|
2012-02-17 10:12:53 +01:00
|
|
|
# Things need to be setup first, usually setup.py initializes everything.
|
|
|
|
# but if e.g. called from command line, we take care of default values here:
|
|
|
|
if not OLITestLib.cred_file:
|
|
|
|
OLITestLib(cred_file='./test/credentials.conf', cmd='./offlineimap.py')
|
|
|
|
|
|
|
|
|
2012-01-09 13:12:28 +01:00
|
|
|
def setUpModule():
|
|
|
|
logging.info("Set Up test module %s" % __name__)
|
|
|
|
tdir = OLITestLib.create_test_dir(suffix=__name__)
|
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
2012-01-09 13:12:28 +01:00
|
|
|
def tearDownModule():
|
|
|
|
logging.info("Tear Down test module")
|
|
|
|
OLITestLib.delete_test_dir()
|
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
|
|
|
# Stuff that can be used
|
|
|
|
# self.assertEqual(self.seq, range(10))
|
2012-01-09 13:12:28 +01:00
|
|
|
# should raise an exception for an immutable sequence
|
2020-08-29 20:27:10 +02:00
|
|
|
# self.assertRaises(TypeError, random.shuffle, (1,2,3))
|
|
|
|
# self.assertTrue(element in self.seq)
|
|
|
|
# self.assertFalse(element in self.seq)
|
2012-01-09 13:12:28 +01:00
|
|
|
|
|
|
|
class TestBasicFunctions(unittest.TestCase):
|
2015-03-23 12:16:53 +01:00
|
|
|
def setUp(self):
|
|
|
|
OLITestLib.delete_remote_testfolders()
|
2012-01-09 13:12:28 +01:00
|
|
|
|
2015-03-23 12:16:53 +01:00
|
|
|
def tearDown(self):
|
|
|
|
OLITestLib.delete_remote_testfolders()
|
2012-01-09 13:12:28 +01:00
|
|
|
|
|
|
|
def test_01_olistartup(self):
|
|
|
|
"""Tests if OLI can be invoked without exceptions
|
|
|
|
|
2015-03-23 12:17:45 +01:00
|
|
|
Cleans existing remote test folders. Then syncs all "OLItest*
|
2012-02-17 10:12:53 +01:00
|
|
|
(specified in the default config) to our local Maildir. The
|
|
|
|
result should be 0 folders and 0 mails."""
|
2012-01-09 13:12:28 +01:00
|
|
|
code, res = OLITestLib.run_OLI()
|
|
|
|
self.assertEqual(res, "")
|
2012-01-20 15:55:44 +01:00
|
|
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertTrue((boxes, mails) == (0, 0), msg="Expected 0 folders and 0 "
|
|
|
|
"mails, but sync led to {0} folders and {1} mails".format(
|
|
|
|
boxes, mails))
|
2012-01-09 13:12:28 +01:00
|
|
|
|
2012-01-20 15:55:44 +01:00
|
|
|
def test_02_createdir(self):
|
2015-03-23 18:20:46 +01:00
|
|
|
"""Create local 'OLItest 1', sync"""
|
2020-08-29 20:27:10 +02:00
|
|
|
OLITestLib.delete_maildir('') # Delete all local maildir folders
|
2015-03-23 18:20:46 +01:00
|
|
|
OLITestLib.create_maildir('INBOX.OLItest 1')
|
|
|
|
code, res = OLITestLib.run_OLI()
|
|
|
|
self.assertEqual(res, "")
|
|
|
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
|
|
|
|
"mails, but sync led to {0} folders and {1} mails".format(
|
|
|
|
boxes, mails))
|
2015-03-23 18:20:46 +01:00
|
|
|
|
|
|
|
def test_03_createdir_quote(self):
|
|
|
|
"""Create local 'OLItest "1"' maildir, sync
|
2012-01-09 13:12:28 +01:00
|
|
|
|
2012-01-20 15:55:44 +01:00
|
|
|
Folder names with quotes used to fail and have been fixed, so
|
|
|
|
one is included here as a small challenge."""
|
2020-08-29 20:27:10 +02:00
|
|
|
OLITestLib.delete_maildir('') # Delete all local maildir folders
|
2012-01-20 15:55:44 +01:00
|
|
|
OLITestLib.create_maildir('INBOX.OLItest "1"')
|
2012-01-09 13:12:28 +01:00
|
|
|
code, res = OLITestLib.run_OLI()
|
2015-03-23 18:20:46 +01:00
|
|
|
if 'unallowed folder' in res:
|
|
|
|
raise unittest.SkipTest("remote server doesn't handle quote")
|
2012-01-09 13:12:28 +01:00
|
|
|
self.assertEqual(res, "")
|
2012-01-20 15:55:44 +01:00
|
|
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertTrue((boxes, mails) == (1, 0), msg="Expected 1 folders and 0 "
|
|
|
|
"mails, but sync led to {0} folders and {1} mails".format(
|
|
|
|
boxes, mails))
|
2012-02-16 11:45:18 +01:00
|
|
|
|
2015-03-23 18:20:46 +01:00
|
|
|
def test_04_nametransmismatch(self):
|
2012-02-16 11:45:18 +01:00
|
|
|
"""Create mismatching remote and local nametrans rules
|
|
|
|
|
|
|
|
This should raise an error."""
|
|
|
|
config = OLITestLib.get_default_config()
|
|
|
|
config.set('Repository IMAP', 'nametrans',
|
2020-08-29 20:27:10 +02:00
|
|
|
'lambda f: f')
|
2012-02-16 11:45:18 +01:00
|
|
|
config.set('Repository Maildir', 'nametrans',
|
2020-08-29 20:27:10 +02:00
|
|
|
'lambda f: f + "moo"')
|
2012-02-16 11:45:18 +01:00
|
|
|
OLITestLib.write_config_file(config)
|
|
|
|
code, res = OLITestLib.run_OLI()
|
2020-08-29 20:27:10 +02:00
|
|
|
# logging.warn("%s %s "% (code, res))
|
2012-02-16 11:45:18 +01:00
|
|
|
# We expect an INFINITE FOLDER CREATION WARNING HERE....
|
|
|
|
mismatch = "ERROR: INFINITE FOLDER CREATION DETECTED!" in res
|
2012-02-17 10:12:53 +01:00
|
|
|
self.assertEqual(mismatch, True, msg="Mismatching nametrans rules did "
|
2020-08-29 20:27:10 +02:00
|
|
|
"NOT trigger an 'infinite folder generation' error. Output was:\n"
|
|
|
|
"{0}".format(res))
|
2012-02-24 09:39:39 +01:00
|
|
|
# Write out default config file again
|
|
|
|
OLITestLib.write_config_file()
|
2012-02-17 10:12:53 +01:00
|
|
|
|
2015-03-23 18:20:46 +01:00
|
|
|
def test_05_createmail(self):
|
2012-02-24 09:39:39 +01:00
|
|
|
"""Create mail in OLItest 1, sync, wipe folder sync
|
|
|
|
|
|
|
|
Currently, this will mean the folder will be recreated
|
|
|
|
locally. At some point when remote folder deletion is
|
|
|
|
implemented, this behavior will change."""
|
|
|
|
OLITestLib.delete_remote_testfolders()
|
2020-08-29 20:27:10 +02:00
|
|
|
OLITestLib.delete_maildir('') # Delete all local maildir folders
|
2012-02-24 09:39:39 +01:00
|
|
|
OLITestLib.create_maildir('INBOX.OLItest')
|
|
|
|
OLITestLib.create_mail('INBOX.OLItest')
|
|
|
|
code, res = OLITestLib.run_OLI()
|
2020-08-29 20:27:10 +02:00
|
|
|
# logging.warn("%s %s "% (code, res))
|
2012-02-24 09:39:39 +01:00
|
|
|
self.assertEqual(res, "")
|
|
|
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertTrue((boxes, mails) == (1, 1), msg="Expected 1 folders and 1 "
|
|
|
|
"mails, but sync led to {0} folders and {1} mails".format(
|
|
|
|
boxes, mails))
|
2012-02-24 09:39:39 +01:00
|
|
|
# The local Mail should have been assigned a proper UID now, check!
|
|
|
|
uids = OLITestLib.get_maildir_uids('INBOX.OLItest')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertFalse(None in uids, msg="All mails should have been " + \
|
|
|
|
"assigned the IMAP's UID number, but {0} messages had no valid ID " \
|
|
|
|
.format(len([None for x in uids if x == None])))
|
2012-05-08 16:41:21 +02:00
|
|
|
|
2015-03-23 18:20:46 +01:00
|
|
|
def test_06_createfolders(self):
|
2012-05-08 16:41:21 +02:00
|
|
|
"""Test if createfolders works as expected
|
|
|
|
|
|
|
|
Create a local Maildir, then sync with remote "createfolders"
|
|
|
|
disabled. Delete local Maildir and sync. We should have no new
|
|
|
|
local maildir then. TODO: Rewrite this test to directly test
|
|
|
|
and count the remote folders when the helper functions have
|
|
|
|
been written"""
|
|
|
|
config = OLITestLib.get_default_config()
|
|
|
|
config.set('Repository IMAP', 'createfolders',
|
2020-08-29 20:27:10 +02:00
|
|
|
'False')
|
2012-05-08 16:41:21 +02:00
|
|
|
OLITestLib.write_config_file(config)
|
|
|
|
|
|
|
|
# delete all remote and local testfolders
|
|
|
|
OLITestLib.delete_remote_testfolders()
|
|
|
|
OLITestLib.delete_maildir('')
|
|
|
|
OLITestLib.create_maildir('INBOX.OLItest')
|
|
|
|
code, res = OLITestLib.run_OLI()
|
2020-08-29 20:27:10 +02:00
|
|
|
# logging.warn("%s %s "% (code, res))
|
2012-05-08 16:41:21 +02:00
|
|
|
self.assertEqual(res, "")
|
|
|
|
OLITestLib.delete_maildir('INBOX.OLItest')
|
|
|
|
code, res = OLITestLib.run_OLI()
|
2015-03-23 14:26:46 +01:00
|
|
|
self.assertEqual(res, "")
|
2012-05-08 16:41:21 +02:00
|
|
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
2020-08-29 20:27:10 +02:00
|
|
|
self.assertTrue((boxes, mails) == (0, 0), msg="Expected 0 folders and 0 "
|
|
|
|
"mails, but sync led to {} folders and {} mails".format(
|
|
|
|
boxes, mails))
|