2012-04-03 01:34:59 +02: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
|
|
|
|
|
2020-08-29 21:10:16 +02:00
|
|
|
from test.OLItest import OLITestLib
|
2012-04-03 01:34:59 +02:00
|
|
|
from offlineimap import imaputil
|
|
|
|
from offlineimap.ui import UI_LIST, setglobalui
|
|
|
|
|
|
|
|
|
|
|
|
# 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')
|
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
2012-04-03 01:34:59 +02:00
|
|
|
def setUpModule():
|
|
|
|
logging.info("Set Up test module %s" % __name__)
|
2020-08-30 12:17:41 +02:00
|
|
|
OLITestLib.create_test_dir(suffix=__name__)
|
2012-04-03 01:34:59 +02:00
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
2012-04-03 01:34:59 +02:00
|
|
|
def tearDownModule():
|
|
|
|
logging.info("Tear Down test module")
|
|
|
|
# comment out next line to keep testdir after test runs. TODO: make nicer
|
|
|
|
OLITestLib.delete_test_dir()
|
|
|
|
|
2020-08-29 20:27:10 +02:00
|
|
|
|
|
|
|
# Stuff that can be used
|
|
|
|
# self.assertEqual(self.seq, range(10))
|
2012-04-03 01:34:59 +02: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-04-03 01:34:59 +02:00
|
|
|
|
|
|
|
class TestInternalFunctions(unittest.TestCase):
|
|
|
|
"""While the other test files test OfflineImap as a program, these
|
|
|
|
tests directly invoke internal helper functions to guarantee that
|
|
|
|
they deliver results as expected"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2020-08-29 20:27:10 +02:00
|
|
|
# This is run before all tests in this class
|
|
|
|
config = OLITestLib.get_default_config()
|
2012-04-03 01:34:59 +02:00
|
|
|
setglobalui(UI_LIST['quiet'](config))
|
|
|
|
|
|
|
|
def test_01_imapsplit(self):
|
|
|
|
"""Test imaputil.imapsplit()"""
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.imapsplit('(\\HasNoChildren) "." "INBOX.Sent"')
|
|
|
|
self.assertEqual(res, ['(\\HasNoChildren)', '"."', '"INBOX.Sent"'])
|
2012-04-03 01:34:59 +02:00
|
|
|
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.imapsplit('"mo\\" o" sdfsdf')
|
|
|
|
self.assertEqual(res, ['"mo\\" o"', 'sdfsdf'])
|
2012-04-19 17:15:56 +02:00
|
|
|
|
2012-04-03 01:34:59 +02:00
|
|
|
def test_02_flagsplit(self):
|
|
|
|
"""Test imaputil.flagsplit()"""
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flagsplit('(\\Draft \\Deleted)')
|
|
|
|
self.assertEqual(res, ['\\Draft', '\\Deleted'])
|
2012-04-03 01:34:59 +02:00
|
|
|
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flagsplit('(FLAGS (\\Seen Old) UID 4807)')
|
|
|
|
self.assertEqual(res, ['FLAGS', '(\\Seen Old)', 'UID', '4807'])
|
2012-04-03 01:34:59 +02:00
|
|
|
|
|
|
|
def test_04_flags2hash(self):
|
|
|
|
"""Test imaputil.flags2hash()"""
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flags2hash('(FLAGS (\\Seen Old) UID 4807)')
|
|
|
|
self.assertEqual(res, {'FLAGS': '(\\Seen Old)', 'UID': '4807'})
|
2012-04-03 01:34:59 +02:00
|
|
|
|
|
|
|
def test_05_flagsimap2maildir(self):
|
|
|
|
"""Test imaputil.flagsimap2maildir()"""
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flagsimap2maildir('(\\Draft \\Deleted)')
|
|
|
|
self.assertEqual(res, set('DT'))
|
2012-04-03 01:34:59 +02:00
|
|
|
|
|
|
|
def test_06_flagsmaildir2imap(self):
|
|
|
|
"""Test imaputil.flagsmaildir2imap()"""
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flagsmaildir2imap(set('DR'))
|
|
|
|
self.assertEqual(res, '(\\Answered \\Draft)')
|
2012-04-03 01:34:59 +02:00
|
|
|
# test all possible flags
|
2020-10-25 18:11:01 +01:00
|
|
|
res = imaputil.flagsmaildir2imap(set('SRFTD'))
|
|
|
|
self.assertEqual(res, '(\\Answered \\Deleted \\Draft \\Flagged \\Seen)')
|
2012-04-03 01:34:59 +02:00
|
|
|
|
|
|
|
def test_07_uid_sequence(self):
|
|
|
|
"""Test imaputil.uid_sequence()"""
|
2020-08-29 20:27:10 +02:00
|
|
|
res = imaputil.uid_sequence([1, 2, 3, 4, 5, 10, 12, 13])
|
2020-10-25 18:11:01 +01:00
|
|
|
self.assertEqual(res, '1:5,10,12:13')
|