Merge branch 'pilou--tests1' into next
This commit is contained in:
commit
3a056519f9
@ -46,8 +46,6 @@ class UsefulIMAPMixIn(object):
|
|||||||
not force:
|
not force:
|
||||||
# No change; return.
|
# No change; return.
|
||||||
return
|
return
|
||||||
# Wipe out all old responses, to maintain semantics with old imaplib2
|
|
||||||
del self.untagged_responses[:]
|
|
||||||
try:
|
try:
|
||||||
result = super(UsefulIMAPMixIn, self).select(mailbox, readonly)
|
result = super(UsefulIMAPMixIn, self).select(mailbox, readonly)
|
||||||
except self.readonly as e:
|
except self.readonly as e:
|
||||||
|
@ -148,20 +148,28 @@ class OLITestLib():
|
|||||||
assert res_t == 'OK'
|
assert res_t == 'OK'
|
||||||
dirs = []
|
dirs = []
|
||||||
for d in data:
|
for d in data:
|
||||||
m = re.search(br''' # Find last quote
|
if d == '':
|
||||||
"((?: # Non-tripple quoted can contain...
|
continue
|
||||||
[^"] | # a non-quote
|
if isinstance(d, tuple):
|
||||||
\\" # a backslashded quote
|
# literal (unquoted)
|
||||||
)*)" # closing quote
|
folder = b'"%s"' % d[1].replace('"', '\\"')
|
||||||
[^"]*$ # followed by no more quotes
|
else:
|
||||||
''', d, flags=re.VERBOSE)
|
m = re.search(br'''
|
||||||
folder = bytearray(m.group(1))
|
[ ] # 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('dir'))
|
||||||
|
if not m.group('quote'):
|
||||||
|
folder = '"%s"' % folder
|
||||||
#folder = folder.replace(br'\"', b'"') # remove quoting
|
#folder = folder.replace(br'\"', b'"') # remove quoting
|
||||||
dirs.append(folder)
|
dirs.append(folder)
|
||||||
# 2) filter out those not starting with INBOX.OLItest and del...
|
# 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:
|
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"\
|
assert res_t == 'OK', "Folder deletion of {0} failed with error"\
|
||||||
":\n{1} {2}".format(folder.decode('utf-8'), res_t, data)
|
":\n{1} {2}".format(folder.decode('utf-8'), res_t, data)
|
||||||
imapobj.logout()
|
imapobj.logout()
|
||||||
|
@ -38,5 +38,5 @@ localfolders =
|
|||||||
type=IMAP
|
type=IMAP
|
||||||
# Don't hammer the server with too many connection attempts:
|
# Don't hammer the server with too many connection attempts:
|
||||||
maxconnections=1
|
maxconnections=1
|
||||||
folderfilter= lambda f: f.startswith('INBOX.OLItest')
|
folderfilter= lambda f: f.startswith('INBOX.OLItest') or f.startswith('INBOX/OLItest')
|
||||||
""")
|
""")
|
||||||
|
@ -31,7 +31,6 @@ def setUpModule():
|
|||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
logging.info("Tear Down test module")
|
logging.info("Tear Down test module")
|
||||||
# comment out next line to keep testdir after test runs. TODO: make nicer
|
|
||||||
OLITestLib.delete_test_dir()
|
OLITestLib.delete_test_dir()
|
||||||
|
|
||||||
#Stuff that can be used
|
#Stuff that can be used
|
||||||
@ -42,27 +41,18 @@ def tearDownModule():
|
|||||||
#self.assertFalse(element in self.seq)
|
#self.assertFalse(element in self.seq)
|
||||||
|
|
||||||
class TestBasicFunctions(unittest.TestCase):
|
class TestBasicFunctions(unittest.TestCase):
|
||||||
#@classmethod
|
def setUp(self):
|
||||||
#def setUpClass(cls):
|
OLITestLib.delete_remote_testfolders()
|
||||||
#This is run before all tests in this class
|
|
||||||
# cls._connection = createExpensiveConnectionObject()
|
|
||||||
|
|
||||||
#@classmethod
|
def tearDown(self):
|
||||||
#This is run after all tests in this class
|
OLITestLib.delete_remote_testfolders()
|
||||||
#def tearDownClass(cls):
|
|
||||||
# cls._connection.destroy()
|
|
||||||
|
|
||||||
# This will be run before each test
|
|
||||||
#def setUp(self):
|
|
||||||
# self.seq = range(10)
|
|
||||||
|
|
||||||
def test_01_olistartup(self):
|
def test_01_olistartup(self):
|
||||||
"""Tests if OLI can be invoked without exceptions
|
"""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
|
(specified in the default config) to our local Maildir. The
|
||||||
result should be 0 folders and 0 mails."""
|
result should be 0 folders and 0 mails."""
|
||||||
OLITestLib.delete_remote_testfolders()
|
|
||||||
code, res = OLITestLib.run_OLI()
|
code, res = OLITestLib.run_OLI()
|
||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
boxes, mails = OLITestLib.count_maildir_mails('')
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
||||||
@ -71,21 +61,33 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
boxes, mails))
|
boxes, mails))
|
||||||
|
|
||||||
def test_02_createdir(self):
|
def test_02_createdir(self):
|
||||||
"""Create local OLItest 1 & OLItest "1" maildir, sync
|
"""Create local 'OLItest 1', sync"""
|
||||||
|
OLITestLib.delete_maildir('') #Delete all local maildir folders
|
||||||
Folder names with quotes used to fail and have been fixed, so
|
|
||||||
one is included here as a small challenge."""
|
|
||||||
OLITestLib.create_maildir('INBOX.OLItest 1')
|
OLITestLib.create_maildir('INBOX.OLItest 1')
|
||||||
OLITestLib.create_maildir('INBOX.OLItest "1"')
|
|
||||||
code, res = OLITestLib.run_OLI()
|
code, res = OLITestLib.run_OLI()
|
||||||
#logging.warn("%s %s "% (code, res))
|
|
||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
boxes, mails = OLITestLib.count_maildir_mails('')
|
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(
|
"mails, but sync led to {0} folders and {1} mails".format(
|
||||||
boxes, mails))
|
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
|
"""Create mismatching remote and local nametrans rules
|
||||||
|
|
||||||
This should raise an error."""
|
This should raise an error."""
|
||||||
@ -106,7 +108,7 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
OLITestLib.write_config_file()
|
OLITestLib.write_config_file()
|
||||||
|
|
||||||
|
|
||||||
def test_04_createmail(self):
|
def test_05_createmail(self):
|
||||||
"""Create mail in OLItest 1, sync, wipe folder sync
|
"""Create mail in OLItest 1, sync, wipe folder sync
|
||||||
|
|
||||||
Currently, this will mean the folder will be recreated
|
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 "\
|
"assigned the IMAP's UID number, but {0} messages had no valid ID "\
|
||||||
.format(len([None for x in uids if x==None])))
|
.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
|
"""Test if createfolders works as expected
|
||||||
|
|
||||||
Create a local Maildir, then sync with remote "createfolders"
|
Create a local Maildir, then sync with remote "createfolders"
|
||||||
@ -151,6 +153,7 @@ class TestBasicFunctions(unittest.TestCase):
|
|||||||
self.assertEqual(res, "")
|
self.assertEqual(res, "")
|
||||||
OLITestLib.delete_maildir('INBOX.OLItest')
|
OLITestLib.delete_maildir('INBOX.OLItest')
|
||||||
code, res = OLITestLib.run_OLI()
|
code, res = OLITestLib.run_OLI()
|
||||||
|
self.assertEqual(res, "")
|
||||||
boxes, mails = OLITestLib.count_maildir_mails('')
|
boxes, mails = OLITestLib.count_maildir_mails('')
|
||||||
self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0 "
|
self.assertTrue((boxes, mails)==(0,0), msg="Expected 0 folders and 0 "
|
||||||
"mails, but sync led to {} folders and {} mails".format(
|
"mails, but sync led to {} folders and {} mails".format(
|
||||||
|
Loading…
Reference in New Issue
Block a user