~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/testing/helpers.py

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Various test helpers."""
19
19
 
20
 
from __future__ import absolute_import, print_function, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
20
__all__ = [
24
21
    'LogFileMark',
25
22
    'TestableMaster',
60
57
from email import message_from_string
61
58
from httplib2 import Http
62
59
from lazr.config import as_timedelta
63
 
from urllib import urlencode
64
 
from urllib2 import HTTPError
65
 
from zope import event
66
 
from zope.component import getUtility
67
 
 
68
60
from mailman.bin.master import Loop as Master
69
61
from mailman.config import config
70
62
from mailman.database.transaction import transaction
75
67
from mailman.interfaces.usermanager import IUserManager
76
68
from mailman.runners.digest import DigestRunner
77
69
from mailman.utilities.mailbox import Mailbox
 
70
from six.moves.urllib_error import HTTPError
 
71
from six.moves.urllib_parse import urlencode
 
72
from zope import event
 
73
from zope.component import getUtility
78
74
 
79
75
 
80
76
NL = '\n'
335
331
    basic_auth = '{0}:{1}'.format(
336
332
        (config.webservice.admin_user if username is None else username),
337
333
        (config.webservice.admin_pass if password is None else password))
338
 
    headers['Authorization'] = 'Basic ' + b64encode(basic_auth)
 
334
    # b64encode() requires a bytes, but the header value must be str.  Do the
 
335
    # necessary conversion dances.
 
336
    token = b64encode(basic_auth.encode('utf-8')).decode('ascii')
 
337
    headers['Authorization'] = 'Basic ' + token
339
338
    response, content = Http().request(url, method, data, headers)
340
339
    # If we did not get a 2xx status code, make this look like a urllib2
341
340
    # exception, for backward compatibility with existing doctests.
470
469
    """
471
470
    # Reset the database between tests.
472
471
    config.db._reset()
473
 
    # Remove any digest files.
 
472
    # Remove any digest files and members.txt file (for the file-recips
 
473
    # handler) in the lists' data directories.
474
474
    for dirpath, dirnames, filenames in os.walk(config.LIST_DATA_DIR):
475
475
        for filename in filenames:
476
 
            if filename.endswith('.mmdf'):
 
476
            if filename.endswith('.mmdf') or filename == 'members.txt':
477
477
                os.remove(os.path.join(dirpath, filename))
478
478
    # Remove all residual queue files.
479
479
    for dirpath, dirnames, filenames in os.walk(config.QUEUE_DIR):
508
508
    """
509
509
    # This mimic what Switchboard.dequeue() does when parsing a message from
510
510
    # text into a Message instance.
511
 
    text = unicode_text.encode('ascii')
512
 
    original_size = len(text)
513
 
    message = message_from_string(text, Message)
 
511
    original_size = len(unicode_text)
 
512
    message = message_from_string(unicode_text, Message)
514
513
    message.original_size = original_size
515
514
    return message
516
515