本文整理汇总了Python中mailman.testing.helpers.LogFileMark.read方法的典型用法代码示例。如果您正苦于以下问题:Python LogFileMark.read方法的具体用法?Python LogFileMark.read怎么用?Python LogFileMark.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailman.testing.helpers.LogFileMark
的用法示例。
在下文中一共展示了LogFileMark.read方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hold_chain
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_hold_chain(self):
msg = mfs("""\
From: [email protected]
To: [email protected]
Subject: A message
Message-ID: <ant>
MIME-Version: 1.0
A message body.
""")
msgdata = dict(moderation_reasons=[
'TEST-REASON-1',
'TEST-REASON-2',
])
logfile = LogFileMark('mailman.vette')
process_chain(self._mlist, msg, msgdata, start_chain='hold')
messages = get_queue_messages('virgin', expected_count=2)
payloads = {}
for item in messages:
if item.msg['to'] == '[email protected]':
part = item.msg.get_payload(0)
payloads['owner'] = part.get_payload().splitlines()
elif item.msg['To'] == '[email protected]':
payloads['sender'] = item.msg.get_payload().splitlines()
else:
self.fail('Unexpected message: %s' % item.msg)
self.assertIn(' TEST-REASON-1', payloads['owner'])
self.assertIn(' TEST-REASON-2', payloads['owner'])
self.assertIn(' TEST-REASON-1', payloads['sender'])
self.assertIn(' TEST-REASON-2', payloads['sender'])
logged = logfile.read()
self.assertIn('TEST-REASON-1', logged)
self.assertIn('TEST-REASON-2', logged)
示例2: test_non_ascii_message
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_non_ascii_message(self):
msg = Message()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Content-Type'] = 'multipart/mixed'
msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
'plain', 'utf-8'))
mbox = digest_mbox(self._mlist)
mbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
mbox.add(msg.as_string())
self._digestq.enqueue(
msg,
listname=self._mlist.fqdn_listname,
digest_path=mbox_path,
volume=1, digest_number=1)
# Use any error logs as the error message if the test fails.
error_log = LogFileMark('mailman.error')
self._runner.run()
# The runner will send the file to the shunt queue on exception.
self.assertEqual(len(self._shuntq.files), 0, error_log.read())
# There are two messages in the virgin queue: the digest as plain-text
# and as multipart.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 2)
self.assertEqual(
sorted(item.msg.get_content_type() for item in messages),
['multipart/mixed', 'text/plain'])
for item in messages:
self.assertEqual(item.msg['subject'],
'Test Digest, Vol 1, Issue 1')
示例3: test_digest_messages
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_digest_messages(self):
# In LP: #1130697, the digest runner creates MIME digests using the
# stdlib MIMEMutlipart class, however this class does not have the
# extended attributes we require (e.g. .sender). The fix is to use a
# subclass of MIMEMultipart and our own Message subclass; this adds
# back the required attributes. (LP: #1130696)
#
# Start by creating the raw ingredients for the digests. This also
# runs the digest runner, thus producing the digest messages into the
# virgin queue.
make_digest_messages(self._mlist)
# Run the virgin queue processor, which runs the cook-headers and
# to-outgoing handlers. This should produce no error.
error_log = LogFileMark('mailman.error')
runner = make_testable_runner(VirginRunner, 'virgin')
runner.run()
error_text = error_log.read()
self.assertEqual(len(error_text), 0, error_text)
self.assertEqual(len(get_queue_messages('shunt')), 0)
messages = get_queue_messages('out')
self.assertEqual(len(messages), 2)
# Which one is the MIME digest?
mime_digest = None
for bag in messages:
if bag.msg.get_content_type() == 'multipart/mixed':
assert mime_digest is None, 'Found two MIME digests'
mime_digest = bag.msg
# The cook-headers handler ran.
self.assertIn('x-mailman-version', mime_digest)
self.assertEqual(mime_digest['precedence'], 'list')
# The list's -request address is the original sender.
self.assertEqual(bag.msgdata['original_sender'],
'[email protected]')
示例4: test_non_ascii_message
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_non_ascii_message(self):
msg = Message()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Content-Type'] = 'multipart/mixed'
msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
'plain', 'utf-8'))
mbox = digest_mbox(self._mlist)
mbox.add(msg.as_string())
# Use any error logs as the error message if the test fails.
error_log = LogFileMark('mailman.error')
make_digest_messages(self._mlist, msg)
# The runner will send the file to the shunt queue on exception.
self.assertEqual(len(self._shuntq.files), 0, error_log.read())
self._check_virgin_queue()
示例5: test_broken_archiver
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_broken_archiver(self):
# GL issue #208 - IArchive messages raise exceptions, breaking the
# rfc-2369 handler and shunting messages.
mark = LogFileMark('mailman.archiver')
self._archiveq.enqueue(
self._msg, {},
listid=self._mlist.list_id,
received_time=now())
IListArchiverSet(self._mlist).get('broken').is_enabled = True
self._runner.run()
# The archiver is broken, so there are no messages on the file system,
# but there is a log message and the message was not shunted.
log_messages = mark.read()
self.assertIn('Exception in "broken" archiver', log_messages)
self.assertIn('RuntimeError: Cannot archive message', log_messages)
get_queue_messages('shunt', expected_count=0)
示例6: test_broken_permalink
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_broken_permalink(self):
# GL issue #208 - IArchive messages raise exceptions, breaking the
# rfc-2369 handler and shunting messages.
site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en')
os.makedirs(site_dir)
footer_path = os.path.join(site_dir, 'myfooter.txt')
with open(footer_path, 'w', encoding='utf-8') as fp:
print('${broken_url}', file=fp)
self._mlist.footer_uri = 'mailman:///myfooter.txt'
self._mlist.preferred_language = 'en'
mark = LogFileMark('mailman.archiver')
decorate.process(self._mlist, self._msg, {})
log_messages = mark.read()
self.assertNotIn('http:', self._msg.as_string())
self.assertIn('Exception in "broken" archiver', log_messages)
self.assertIn('RuntimeError: Cannot get permalink', log_messages)
示例7: test_non_ascii_message
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_non_ascii_message(self):
# Subscribe some users receiving digests.
anne = subscribe(self._mlist, 'Anne')
anne.preferences.delivery_mode = DeliveryMode.mime_digests
bart = subscribe(self._mlist, 'Bart')
bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
msg = Message()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Content-Type'] = 'multipart/mixed'
msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
'plain', 'utf-8'))
mbox = digest_mbox(self._mlist)
mbox.add(msg.as_string())
# Use any error logs as the error message if the test fails.
error_log = LogFileMark('mailman.error')
make_digest_messages(self._mlist, msg)
# The runner will send the file to the shunt queue on exception.
self.assertEqual(len(self._shuntq.files), 0, error_log.read())
self._check_virgin_queue()
示例8: test_broken_archiver
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_broken_archiver(self):
# GL issue #208 - IArchive messages raise exceptions, breaking the
# rfc-2369 handler and shunting messages.
config.push('archiver', """
[archiver.broken]
class: {}.BrokenArchiver
enable: yes
""".format(BrokenArchiver.__module__))
self.addCleanup(config.pop, 'archiver')
mark = LogFileMark('mailman.archiver')
rfc_2369.process(self._mlist, self._msg, {})
log_messages = mark.read()
# Because .list_url() was broken, there will be no List-Archive header.
self.assertIsNone(self._msg.get('list-archive'))
self.assertIn('Exception in "broken" archiver', log_messages)
self.assertIn('RuntimeError: Cannot get list URL', log_messages)
# Because .permalink() was broken, there will be no Archived-At header.
self.assertIsNone(self._msg.get('archived-at'))
self.assertIn('Exception in "broken" archiver', log_messages)
self.assertIn('RuntimeError: Cannot get permalink', log_messages)
示例9: test_log_exception_in_finish
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_log_exception_in_finish(self):
# If something bad happens in .finish(), the traceback should get
# logged. LP: #1165589.
msg = mfs("""\
From: [email protected]
To: [email protected]
Message-ID: <ant>
""")
switchboard = config.switchboards['shunt']
# Enqueue the message.
filebase = switchboard.enqueue(msg)
error_log = LogFileMark('mailman.error')
msg, data = switchboard.dequeue(filebase)
# Now, cause .finish() to throw an exception.
with patch('mailman.core.switchboard.os.rename',
side_effect=OSError('Oops!')):
switchboard.finish(filebase, preserve=True)
traceback = error_log.read().splitlines()
self.assertEqual(traceback[1], 'Traceback (most recent call last):')
self.assertEqual(traceback[-1], 'OSError: Oops!')
示例10: test_digest_messages
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_digest_messages(self):
# In LP: #1130697, the digest runner creates MIME digests using the
# stdlib MIMEMutlipart class, however this class does not have the
# extended attributes we require (e.g. .sender). The fix is to use a
# subclass of MIMEMultipart and our own Message subclass; this adds
# back the required attributes. (LP: #1130696)
self._mlist.send_welcome_message = False
# Subscribe some users receiving digests.
anne = subscribe(self._mlist, 'Anne')
anne.preferences.delivery_mode = DeliveryMode.mime_digests
bart = subscribe(self._mlist, 'Bart')
bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
# Start by creating the raw ingredients for the digests. This also
# runs the digest runner, thus producing the digest messages into the
# virgin queue.
make_digest_messages(self._mlist)
# Run the virgin queue processor, which runs the cook-headers and
# to-outgoing handlers. This should produce no error.
error_log = LogFileMark('mailman.error')
runner = make_testable_runner(VirginRunner, 'virgin')
runner.run()
error_text = error_log.read()
self.assertEqual(len(error_text), 0, error_text)
get_queue_messages('shunt', expected_count=0)
items = get_queue_messages('out', expected_count=2)
# Which one is the MIME digest?
mime_digest = None
for item in items:
if item.msg.get_content_type() == 'multipart/mixed':
assert mime_digest is None, 'Found two MIME digests'
mime_digest = item.msg
# The cook-headers handler ran.
self.assertIn('x-mailman-version', mime_digest)
self.assertEqual(mime_digest['precedence'], 'list')
# The list's -request address is the original sender.
self.assertEqual(item.msgdata['original_sender'],
'[email protected]')
示例11: test_header_matches
# 需要导入模块: from mailman.testing.helpers import LogFileMark [as 别名]
# 或者: from mailman.testing.helpers.LogFileMark import read [as 别名]
def test_header_matches(self):
# This test contail real cases of header_filter_rules
self._pckdict['header_filter_rules'] = [
('X\\-Spam\\-Status\\: Yes.*', 3, False),
('^X-Spam-Status: Yes\r\n\r\n', 2, False),
('^X-Spam-Level: \\*\\*\\*.*$', 3, False),
('^X-Spam-Level:.\\*\\*\r\n^X-Spam:.\\Yes', 3, False),
('Subject: \\[SPAM\\].*', 3, False),
('^Subject: .*loan.*', 3, False),
('Original-Received: from *linkedin.com*\r\n', 3, False),
('X-Git-Module: rhq.*git', 6, False),
('Approved: verysecretpassword', 6, False),
('^Subject: dev-\r\n^Subject: staging-', 3, False),
('from: .*[email protected]\r\nfrom: .*@jw-express.com',
2, False),
('^Received: from smtp-.*\\.fedoraproject\\.org\r\n'
'^Received: from mx.*\\.redhat.com\r\n'
'^Resent-date:\r\n'
'^Resent-from:\r\n'
'^Resent-Message-ID:\r\n'
'^Resent-to:\r\n'
'^Subject: [^mtv]\r\n',
7, False),
('^Received: from fedorahosted\\.org.*by fedorahosted\\.org\r\n'
'^Received: from hosted.*\\.fedoraproject.org.*by '
'hosted.*\\.fedoraproject\\.org\r\n'
'^Received: from hosted.*\\.fedoraproject.org.*by '
'fedoraproject\\.org\r\n'
'^Received: from hosted.*\\.fedoraproject.org.*by '
'fedorahosted\\.org',
6, False),
]
error_log = LogFileMark('mailman.error')
self._import()
self.assertListEqual(
[(hm.header, hm.pattern, hm.chain)
for hm in self._mlist.header_matches], [
('x-spam-status', 'Yes.*', 'discard'),
('x-spam-status', 'Yes', 'reject'),
('x-spam-level', '\\*\\*\\*.*$', 'discard'),
('x-spam-level', '\\*\\*', 'discard'),
('x-spam', '\\Yes', 'discard'),
('subject', '\\[SPAM\\].*', 'discard'),
('subject', '.*loan.*', 'discard'),
('original-received', 'from *linkedin.com*', 'discard'),
('x-git-module', 'rhq.*git', 'accept'),
('approved', 'verysecretpassword', 'accept'),
('subject', 'dev-', 'discard'),
('subject', 'staging-', 'discard'),
('from', '.*[email protected]', 'reject'),
('from', '.*@jw-express.com', 'reject'),
('received', 'from smtp-.*\\.fedoraproject\\.org', 'hold'),
('received', 'from mx.*\\.redhat.com', 'hold'),
('resent-date', '.*', 'hold'),
('resent-from', '.*', 'hold'),
('resent-message-id', '.*', 'hold'),
('resent-to', '.*', 'hold'),
('subject', '[^mtv]', 'hold'),
('received', 'from fedorahosted\\.org.*by fedorahosted\\.org',
'accept'),
('received',
'from hosted.*\\.fedoraproject.org.*by '
'hosted.*\\.fedoraproject\\.org', 'accept'),
('received',
'from hosted.*\\.fedoraproject.org.*by '
'fedoraproject\\.org', 'accept'),
('received',
'from hosted.*\\.fedoraproject.org.*by '
'fedorahosted\\.org', 'accept'),
])
loglines = error_log.read().strip()
self.assertEqual(len(loglines), 0)