当前位置: 首页>>代码示例>>Python>>正文


Python helpers.LogFileMark类代码示例

本文整理汇总了Python中mailman.testing.helpers.LogFileMark的典型用法代码示例。如果您正苦于以下问题:Python LogFileMark类的具体用法?Python LogFileMark怎么用?Python LogFileMark使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LogFileMark类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connect_with_socket_failure

 def test_connect_with_socket_failure(self, class_mock):
     self._nntpq.enqueue(self._msg, {}, listname='[email protected]')
     mark = LogFileMark('mailman.error')
     self._runner.run()
     log_message = mark.readline()[:-1]
     self.assertTrue(log_message.endswith(
         'NNTP socket error for [email protected]'))
开发者ID:aregee,项目名称:Mailman,代码行数:7,代码来源:test_nntp.py

示例2: test_digest_messages

 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]')
开发者ID:aditigupta96,项目名称:mailman3,代码行数:33,代码来源:test_runner.py

示例3: test_hold_chain

    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)
开发者ID:aswinpj,项目名称:Mailman,代码行数:33,代码来源:test_hold.py

示例4: test_non_ascii_message

 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')
开发者ID:adam-iris,项目名称:mailman,代码行数:30,代码来源:test_digest.py

示例5: test_no_detectable_bounce_addresses

    def test_no_detectable_bounce_addresses(self):
        # A bounce message was received, but no addresses could be detected.
        # A message will be logged in the bounce log though, and the message
        # can be forwarded to someone who can do something about it.
        self._mlist.forward_unrecognized_bounces_to = (
            UnrecognizedBounceDisposition.site_owner)
        bogus = message_from_string("""\
From: [email protected]
To: [email protected]
Message-Id: <third>

""")
        self._bounceq.enqueue(bogus, self._msgdata)
        mark = LogFileMark('mailman.bounce')
        self._runner.run()
        self.assertEqual(len(get_queue_messages('bounces')), 0)
        events = list(self._processor.events)
        self.assertEqual(len(events), 0)
        line = mark.readline()
        self.assertEqual(
            line[-51:-1],
            'Bounce message w/no discernable addresses: <third>')
        # Here's the forwarded message to the site owners.
        forwards = get_queue_messages('virgin')
        self.assertEqual(len(forwards), 1)
        self.assertEqual(forwards[0].msg['to'], '[email protected]')
开发者ID:aditigupta96,项目名称:mailman3,代码行数:26,代码来源:test_bounce.py

示例6: test_archive_lock_used

 def test_archive_lock_used(self):
     # Test that locking the maildir when adding works as a failure here
     # could mean we lose mail.
     lock_file = os.path.join(
         config.LOCK_DIR, '{0}-maildir.lock'.format(
             self._mlist.fqdn_listname))
     with Lock(lock_file):
         # Acquire the archiver lock, then make sure the archiver logs the
         # fact that it could not acquire the lock.
         archive_thread = threading.Thread(
             target=Prototype.archive_message,
             args=(self._mlist, self._msg))
         mark = LogFileMark('mailman.error')
         archive_thread.run()
         # Test that the archiver output the correct error.
         line = mark.readline()
         # XXX 2012-03-15 BAW: we really should remove timestamp prefixes
         # from the loggers when under test.
         self.assertTrue(line.endswith(
             'Unable to acquire prototype archiver lock for {0}, '
             'discarding: {1}\n'.format(
                 self._mlist.fqdn_listname,
                 self._msg.get('message-id'))))
     # Check that the message didn't get archived.
     created_files = self._find(config.ARCHIVE_DIR)
     self.assertEqual(self._expected_dir_structure, created_files)
开发者ID:aregee,项目名称:Mailman,代码行数:26,代码来源:test_prototype.py

示例7: test_bad_configuration_line

 def test_bad_configuration_line(self):
     # Take a mark on the error log file.
     mark = LogFileMark('mailman.error')
     # A bad value in [antispam]header_checks should just get ignored, but
     # with an error message logged.
     chain = config.chains['header-match']
     # The links are created dynamically; the rule names will all start
     # with the same prefix, but have a variable suffix.  The actions will
     # all be to jump to the named chain.  Do these checks now, while we
     # collect other useful information.
     post_checks = []
     saw_any_rule = False
     for link in chain.get_links(self._mlist, Message(), {}):
         if link.rule.name == 'any':
             saw_any_rule = True
             self.assertEqual(link.action, LinkAction.jump)
         elif saw_any_rule:
             raise AssertionError("'any' rule was not last")
         else:
             self.assertEqual(link.rule.name[:13], 'header-match-')
             self.assertEqual(link.action, LinkAction.defer)
             post_checks.append((link.rule.header, link.rule.pattern))
     self.assertListEqual(post_checks, [
         ('Foo', 'foo'),
         ('Bar', 'bar'),
         ])
     # Check the error log.
     self.assertEqual(mark.readline()[-77:-1],
                      'Configuration error: [antispam]header_checks '
                      'contains bogus line: A-bad-line')
开发者ID:aregee,项目名称:Mailman,代码行数:30,代码来源:test_headers.py

示例8: test_discarding_pipeline

 def test_discarding_pipeline(self):
     # If a handler in the pipeline raises DiscardMessage, the message will
     # be thrown away, but with a log message.
     mark = LogFileMark('mailman.vette')
     process(self._mlist, self._msg, {}, 'test-discarding')
     line = mark.readline()[:-1]
     self.assertTrue(line.endswith(
         '<ant> discarded by "test-discarding" pipeline handler '
         '"discarding": by test handler'))
开发者ID:aditigupta96,项目名称:mailman3,代码行数:9,代码来源:test_pipelines.py

示例9: test_header_matches_anything

 def test_header_matches_anything(self):
     # Check that a wild card header pattern is skipped.
     self._pckdict['header_filter_rules'] = [
         ('.*', 7, False),
         ]
     error_log = LogFileMark('mailman.error')
     self._import()
     self.assertListEqual(self._mlist.header_matches, [])
     self.assertIn('Unsupported header_filter_rules pattern',
                   error_log.readline())
开发者ID:aswinpj,项目名称:Mailman,代码行数:10,代码来源:test_import.py

示例10: test_header_matches_invalid_re

 def test_header_matches_invalid_re(self):
     # Check that an invalid regular expression pattern is skipped.
     self._pckdict['header_filter_rules'] = [
         ('SomeHeaderName: *invalid-re', 3, False),
         ]
     error_log = LogFileMark('mailman.error')
     self._import()
     self.assertListEqual(self._mlist.header_matches, [])
     self.assertIn('Skipping header_filter rule because of an invalid '
                   'regular expression', error_log.readline())
开发者ID:aswinpj,项目名称:Mailman,代码行数:10,代码来源:test_import.py

示例11: test_header_matches_header_only

 def test_header_matches_header_only(self):
     # Check that an empty pattern is skipped.
     self._pckdict['header_filter_rules'] = [
         ('SomeHeaderName', 3, False),
         ]
     error_log = LogFileMark('mailman.error')
     self._import()
     self.assertListEqual(self._mlist.header_matches, [])
     self.assertIn('Unsupported header_filter_rules pattern',
                   error_log.readline())
开发者ID:aswinpj,项目名称:Mailman,代码行数:10,代码来源:test_import.py

示例12: test_rejecting_pipeline

 def test_rejecting_pipeline(self):
     # If a handler in the pipeline raises DiscardMessage, the message will
     # be thrown away, but with a log message.
     mark = LogFileMark('mailman.vette')
     process(self._mlist, self._msg, {}, 'test-rejecting')
     line = mark.readline()[:-1]
     self.assertTrue(line.endswith(
         '<ant> rejected by "test-rejecting" pipeline handler '
         '"rejecting": by test handler'))
     # In the rejection case, the original message will also be in the
     # virgin queue.
     items = get_queue_messages('virgin', expected_count=1)
     self.assertEqual(str(items[0].msg['subject']), 'a test')
开发者ID:aswinpj,项目名称:Mailman,代码行数:13,代码来源:test_pipelines.py

示例13: test_maybe_forward_discard

 def test_maybe_forward_discard(self):
     # When forward_unrecognized_bounces_to is set to discard, no bounce
     # messages are forwarded.
     self._mlist.forward_unrecognized_bounces_to = (
         UnrecognizedBounceDisposition.discard)
     # The only artifact of this call is a log file entry.
     mark = LogFileMark('mailman.bounce')
     maybe_forward(self._mlist, self._msg)
     get_queue_messages('virgin', expected_count=0)
     line = mark.readline()
     self.assertEqual(
         line[-40:-1],
         'Discarding unrecognized bounce: <first>')
开发者ID:aswinpj,项目名称:Mailman,代码行数:13,代码来源:test_bounces.py

示例14: test_error_with_numeric_port

 def test_error_with_numeric_port(self):
     # Test the code path where a socket.error is raised in the delivery
     # function, and the MTA port is set to zero.  The only real effect of
     # that is a log message.  Start by opening the error log and reading
     # the current file position.
     mark = LogFileMark('mailman.error')
     self._outq.enqueue(self._msg, {}, listid='test.example.com')
     with configuration('mta', smtp_port=2112):
         self._runner.run()
     line = mark.readline()
     # The log line will contain a variable timestamp, the PID, and a
     # trailing newline.  Ignore these.
     self.assertEqual(
         line[-53:-1],
         'Cannot connect to SMTP server localhost on port 2112')
开发者ID:aswinpj,项目名称:Mailman,代码行数:15,代码来源:test_outgoing.py

示例15: test_get_moderator_approval_log_on_hold

 def test_get_moderator_approval_log_on_hold(self):
     # When the subscription is held for moderator approval, a message is
     # logged.
     mark = LogFileMark('mailman.subscribe')
     self._mlist.subscription_policy = SubscriptionPolicy.moderate
     anne = self._user_manager.create_address(self._anne)
     workflow = SubscriptionWorkflow(self._mlist, anne,
                                     pre_verified=True,
                                     pre_confirmed=True)
     # Consume the entire state machine.
     list(workflow)
     self.assertIn(
        '[email protected]: held subscription request from [email protected]',
        mark.readline()
        )
开发者ID:P-EB,项目名称:mailman3-core,代码行数:15,代码来源:test_subscriptions.py


注:本文中的mailman.testing.helpers.LogFileMark类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。