Merge branch 'pilou--tests1' into next

This commit is contained in:
Nicolas Sebrecht 2015-04-02 19:32:37 +02:00
commit 3a056519f9
4 changed files with 47 additions and 38 deletions

View File

@ -46,8 +46,6 @@ class UsefulIMAPMixIn(object):
not force:
# No change; return.
return
# Wipe out all old responses, to maintain semantics with old imaplib2
del self.untagged_responses[:]
try:
result = super(UsefulIMAPMixIn, self).select(mailbox, readonly)
except self.readonly as e:

View File

@ -148,20 +148,28 @@ class OLITestLib():
assert res_t == 'OK'
dirs = []
for d in data:
m = re.search(br''' # Find last quote
"((?: # Non-tripple quoted can contain...
[^"] | # a non-quote
\\" # a backslashded quote
)*)" # closing quote
[^"]*$ # followed by no more quotes
if d == '':
continue
if isinstance(d, tuple):
# literal (unquoted)
folder = b'"%s"' % d[1].replace('"', '\\"')
else:
m = re.search(br'''
[ ] # space
(?P<dir>
(?P<quote>"?) # starting quote
([^"]|\\")* # a non-quote or a backslashded quote
(?P=quote))$ # ending quote
''', d, flags=re.VERBOSE)
folder = bytearray(m.group(1))
folder = bytearray(m.group('dir'))
if not m.group('quote'):
folder = '"%s"' % folder
#folder = folder.replace(br'\"', b'"') # remove quoting
dirs.append(folder)
# 2) filter out those not starting with INBOX.OLItest and del...
dirs = [d for d in dirs if d.startswith(b'INBOX.OLItest')]
dirs = [d for d in dirs if d.startswith(b'"INBOX.OLItest') or d.startswith(b'"INBOX/OLItest')]
for folder in dirs:
res_t, data = imapobj.delete(b'\"'+folder+b'\"')
res_t, data = imapobj.delete(folder)
assert res_t == 'OK', "Folder deletion of {0} failed with error"\
":\n{1} {2}".format(folder.decode('utf-8'), res_t, data)
imapobj.logout()

View File

@ -38,5 +38,5 @@ localfolders =
type=IMAP
# Don't hammer the server with too many connection attempts:
maxconnections=1
folderfilter= lambda f: f.startswith('INBOX.OLItest')
folderfilter= lambda f: f.startswith('INBOX.OLItest') or f.startswith('INBOX/OLItest')
""")

View File

@ -31,7 +31,6 @@ def setUpModule():
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()
#Stuff that can be used
@ -42,27 +41,18 @@ def tearDownModule():
#self.assertFalse(element in self.seq)
class TestBasicFunctions(unittest.TestCase):
#@classmethod
#def setUpClass(cls):
#This is run before all tests in this class
# cls._connection = createExpensiveConnectionObject()
def setUp(self):
OLITestLib.delete_remote_testfolders()
#@classmethod
#This is run after all tests in this class
#def tearDownClass(cls):
# cls._connection.destroy()
# This will be run before each test
#def setUp(self):
# self.seq = range(10)
def tearDown(self):
OLITestLib.delete_remote_testfolders()
def test_01_olistartup(self):
"""Tests if OLI can be invoked without exceptions
Cleans existing remote tet folders. Then syncs all "OLItest*
Cleans existing remote test folders. Then syncs all "OLItest*
(specified in the default config) to our local Maildir. The
result should be 0 folders and 0 mails."""
OLITestLib.delete_remote_testfolders()
code, res = OLITestLib.run_OLI()
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
@ -71,21 +61,33 @@ class TestBasicFunctions(unittest.TestCase):
boxes, mails))
def test_02_createdir(self):
"""Create local OLItest 1 & OLItest "1" maildir, sync
Folder names with quotes used to fail and have been fixed, so
one is included here as a small challenge."""
"""Create local 'OLItest 1', sync"""
OLITestLib.delete_maildir('') #Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest 1')
OLITestLib.create_maildir('INBOX.OLItest "1"')
code, res = OLITestLib.run_OLI()
#logging.warn("%s %s "% (code, res))
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(2,0), msg="Expected 2 folders and 0 "
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))
def test_03_nametransmismatch(self):
def test_03_createdir_quote(self):
"""Create local 'OLItest "1"' maildir, sync
Folder names with quotes used to fail and have been fixed, so
one is included here as a small challenge."""
OLITestLib.delete_maildir('') #Delete all local maildir folders
OLITestLib.create_maildir('INBOX.OLItest "1"')
code, res = OLITestLib.run_OLI()
if 'unallowed folder' in res:
raise unittest.SkipTest("remote server doesn't handle quote")
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
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))
def test_04_nametransmismatch(self):
"""Create mismatching remote and local nametrans rules
This should raise an error."""
@ -106,7 +108,7 @@ class TestBasicFunctions(unittest.TestCase):
OLITestLib.write_config_file()
def test_04_createmail(self):
def test_05_createmail(self):
"""Create mail in OLItest 1, sync, wipe folder sync
Currently, this will mean the folder will be recreated
@ -129,7 +131,7 @@ class TestBasicFunctions(unittest.TestCase):
"assigned the IMAP's UID number, but {0} messages had no valid ID "\
.format(len([None for x in uids if x==None])))
def test_05_createfolders(self):
def test_06_createfolders(self):
"""Test if createfolders works as expected
Create a local Maildir, then sync with remote "createfolders"
@ -151,6 +153,7 @@ class TestBasicFunctions(unittest.TestCase):
self.assertEqual(res, "")
OLITestLib.delete_maildir('INBOX.OLItest')
code, res = OLITestLib.run_OLI()
self.assertEqual(res, "")
boxes, mails = OLITestLib.count_maildir_mails('')
self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0 "
"mails, but sync led to {} folders and {} mails".format(