示例#1
0
def temporary_config(name, settings):
    """Temporarily set a configuration (use in a with-statement)."""
    config.push(name, settings)
    try:
        yield
    finally:
        config.pop(name)
示例#2
0
def temporary_config(name, settings):
    """Temporarily set a configuration (use in a with-statement)."""
    config.push(name, settings)
    try:
        yield
    finally:
        config.pop(name)
示例#3
0
 def test_dispose_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages can be
     # preserved, then this is similar to discarding the message except
     # that a copy is preserved in the 'bad' queue.
     self._mlist.filter_action = FilterAction.preserve
     config.push('preservable', """
     [mailman]
     filtered_messages_are_preservable: yes
     """)
     try:
         mime_delete.dispose(self._mlist, self._msg, {}, 'preserved')
     except errors.DiscardMessage as error:
         pass
     else:
         raise AssertionError('DiscardMessage exception expected')
     finally:
         config.pop('preservable')
     self.assertEqual(error.message, 'preserved')
     # There should be no messages in the 'bad' queue.
     messages = get_queue_messages('bad')
     self.assertEqual(len(messages), 1)
     message = messages[0].msg
     self.assertEqual(message['subject'], 'A disposable message')
     self.assertEqual(message['message-id'], '<ant>')
    def test_invalid_config(self):
        config.push('invalid_config', """\
[mta]
smtp_secure_mode: invalid
""")
        with self.assertRaises(InvalidConfigurationError):
            BaseDeliveryTester()
        config.pop('invalid_config')
    def test_starttls_config(self):
        config.push('starttls_config', """\
[mta]
smtp_secure_mode: starttls
""")
        delivery = BaseDeliveryTester()
        self.assertIsInstance(delivery.connection, Connection)
        config.pop('starttls_config')
示例#6
0
    def test_pushed_section_is_found(self):
        config.push('test config', """\
[archiver.other]
enable: yes
""")
        result = self._command.invoke(conf, ('-k', 'enable'))
        self.assertIn('[archiver.other] enable: yes', result.output)
        config.pop('test config')
示例#7
0
 def tearDown(cls):
     assert cls.var_dir is not None, 'Layer not set up'
     reset_the_world()
     # Destroy the test database after the tests are done so that there is
     # no data in case the tests are rerun with a database layer like mysql
     # or postgresql which are not deleted in teardown.
     config.pop('test config')
     shutil.rmtree(cls.var_dir)
     cls.var_dir = None
示例#8
0
 def test_site_disabled(self):
     # Here the system configuration enables all the archivers in time for
     # the archive set to be created with all list archivers enabled.  But
     # then the site-wide archiver gets disabled, so the list specific
     # archiver will also be disabled.
     archiver_set = IListArchiverSet(self._mlist)
     archiver = archiver_set.get('prototype')
     self.assertTrue(archiver.is_enabled)
     # Disable the site-wide archiver.
     config.push('enable prototype', """\
     [archiver.prototype]
     enable: no
     """)
     self.assertFalse(archiver.is_enabled)
     config.pop('enable prototype')
示例#9
0
 def test_site_disabled(self):
     # Here the system configuration enables all the archivers in time for
     # the archive set to be created with all list archivers enabled.  But
     # then the site-wide archiver gets disabled, so the list specific
     # archiver will also be disabled.
     archiver_set = IListArchiverSet(self._mlist)
     archiver = archiver_set.get('prototype')
     self.assertTrue(archiver.is_enabled)
     # Disable the site-wide archiver.
     config.push('enable prototype', """\
     [archiver.prototype]
     enable: no
     """)
     self.assertFalse(archiver.is_enabled)
     config.pop('enable prototype')
示例#10
0
 def tearDown(cls):
     assert cls.var_dir is not None, 'Layer not set up'
     reset_the_world()
     # Destroy the test database after the tests are done so that there is
     # no data in case the tests are rerun with a database layer like mysql
     # or postgresql which are not deleted in teardown.
     shutil.rmtree(cls.var_dir)
     # Prevent the bit of post-processing on the .pop() that creates
     # directories.  We're basically shutting down everything and we don't
     # need the directories created.  Plus, doing so leaves a var directory
     # turd in the source tree's top-level directory.  We do it this way
     # rather than shutil.rmtree'ing the resulting var directory because
     # it's possible the user created a valid such directory for
     # operational or test purposes.
     config.create_paths = False
     config.pop('test config')
     cls.var_dir = None
示例#11
0
文件: layers.py 项目: maxking/mailman
 def tearDown(cls):
     assert cls.var_dir is not None, 'Layer not set up'
     reset_the_world()
     # Destroy the test database after the tests are done so that there is
     # no data in case the tests are rerun with a database layer like mysql
     # or postgresql which are not deleted in teardown.
     shutil.rmtree(cls.var_dir)
     # Prevent the bit of post-processing on the .pop() that creates
     # directories.  We're basically shutting down everything and we don't
     # need the directories created.  Plus, doing so leaves a var directory
     # turd in the source tree's top-level directory.  We do it this way
     # rather than shutil.rmtree'ing the resulting var directory because
     # it's possible the user created a valid such directory for
     # operational or test purposes.
     config.create_paths = False
     config.pop('test config')
     cls.var_dir = None
示例#12
0
 def test_enable_list_archiver(self):
     # When the system configuration file disables an archiver site-wide,
     # the list-specific mailing list will get initialized as not enabled.
     # Create the archiver set on the fly so that it doesn't get
     # initialized with a configuration that enables the prototype archiver.
     archiver_set = IListArchiverSet(self._mlist)
     archiver = archiver_set.get('prototype')
     self.assertFalse(archiver.is_enabled)
     # Enable both the list archiver and the system archiver.
     archiver.is_enabled = True
     config.push('enable prototype', """\
     [archiver.prototype]
     enable: yes
     """)
     # Get the IListArchiver again.
     archiver = archiver_set.get('prototype')
     self.assertTrue(archiver.is_enabled)
     config.pop('enable prototype')
示例#13
0
 def test_enable_list_archiver(self):
     # When the system configuration file disables an archiver site-wide,
     # the list-specific mailing list will get initialized as not enabled.
     # Create the archiver set on the fly so that it doesn't get
     # initialized with a configuration that enables the prototype archiver.
     archiver_set = IListArchiverSet(self._mlist)
     archiver = archiver_set.get('prototype')
     self.assertFalse(archiver.is_enabled)
     # Enable both the list archiver and the system archiver.
     archiver.is_enabled = True
     config.push('enable prototype', """\
     [archiver.prototype]
     enable: yes
     """)
     # Get the IListArchiver again.
     archiver = archiver_set.get('prototype')
     self.assertTrue(archiver.is_enabled)
     config.pop('enable prototype')
示例#14
0
 def test_dispose_non_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages cannot be
     # preserved, then this is the same as discarding them.
     self._mlist.filter_action = FilterAction.preserve
     config.push('non-preservable', """
     [mailman]
     filtered_messages_are_preservable: no
     """)
     try:
         mime_delete.dispose(self._mlist, self._msg, {}, 'not preserved')
     except errors.DiscardMessage as error:
         pass
     else:
         raise AssertionError('DiscardMessage exception expected')
     finally:
         config.pop('non-preservable')
     self.assertEqual(error.message, 'not preserved')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
示例#15
0
    def test_site_admin_unicode(self):
        # Since the config file is read as bytes, the site_owner is also a
        # bytes and must be converted to unicode when used as a fallback.
        self._cris.unsubscribe()
        self._dave.unsubscribe()
        self.assertEqual(self._mlist.administrators.member_count, 0)
        msgdata = {}
        # In order to properly mimic the testing environment, use
        # config.push()/config.pop() directly instead of using the
        # configuration() context manager.
        config.push('test_site_admin_unicode', b"""\
[mailman]
site_owner: [email protected]
""")
        try:
            self._process(self._mlist, self._msg, msgdata)
        finally:
            config.pop('test_site_admin_unicode')
        self.assertEqual(len(msgdata['recipients']), 1)
        self.assertIsInstance(list(msgdata['recipients'])[0], unicode)
示例#16
0
 def tearDown(self):
     config.pop('test config')
示例#17
0
 def _remove(self):
     config.pop(self._uuid)
示例#18
0
 def tearDown(self):
     config.pop('dispose')
示例#19
0
 def tearDown(self):
     config.pop('password scheme')
     reset_the_world()
示例#20
0
 def tearDown(self):
     config.pop('site owner')
示例#21
0
 def tearDown(self):
     config.pop('no template dir')
     shutil.rmtree(self.var_dir)
示例#22
0
 def _remove(self):
     config.pop(self._uuid)
示例#23
0
 def tearDown(self):
     shutil.rmtree(self._tempdir)
     config.pop('prototype')
示例#24
0
文件: layers.py 项目: bksim/mailman
 def tearDown(cls):
     assert cls.var_dir is not None, 'Layer not set up'
     config.pop('test config')
     shutil.rmtree(cls.var_dir)
     cls.var_dir = None
示例#25
0
 def tearDown(cls):
     assert cls.var_dir is not None, "Layer not set up"
     config.pop("test config")
     shutil.rmtree(cls.var_dir)
     cls.var_dir = None
 def tearDown(cls):
     assert cls.smtpd is not None, 'Layer not set up'
     cls.smtpd.clear()
     cls.smtpd.stop()
     config.pop('starttls')
示例#27
0
 def tearDown(self):
     config.pop('dispose')
示例#28
0
 def tearDown(self):
     config.pop('fake outgoing')
示例#29
0
 def tearDown(self):
     config.pop("template config")
     shutil.rmtree(self.var_dir)
示例#30
0
 def tearDown(self):
     if self.fp is not None:
         self.fp.close()
     config.pop('template config')
     shutil.rmtree(self.var_dir)
示例#31
0
def config_initialize(request):
    # Set up the basic configuration stuff.  Turn off path creation until
    # we've pushed the testing config.
    config.create_paths = False
    initialize.initialize_1(INHIBIT_CONFIG_FILE)
    # Calculate a temporary VAR_DIR directory so that run-time artifacts
    # of the tests won't tread on the installation's data.  This also
    # makes it easier to clean up after the tests are done, and insures
    # isolation of test suite runs.
    var_dir = tempfile.mkdtemp()
    # We need a test configuration both for the foreground process and any
    # child processes that get spawned.  lazr.config would allow us to do
    # it all in a string that gets pushed, and we'll do that for the
    # foreground, but because we may be spawning processes (such as
    # runners) we'll need a file that we can specify to the with the -C
    # option.  Craft the full test configuration string here, push it, and
    # also write it out to a temp file for -C.
    #
    # Create a dummy postfix.cfg file so that the test suite doesn't try
    # to run the actual postmap command, which may not exist anyway.
    postfix_cfg = os.path.join(var_dir, 'postfix.cfg')
    with open(postfix_cfg, 'w') as fp:
        print(dedent("""
        [postfix]
        postmap_command: true
        transport_file_type: hash
        """),
              file=fp)
        test_config = dedent("""
        [mailman]
        layout: testing
        [paths.testing]
        var_dir: {}
        [mta]
        configuration: {}
        [devmode]
        enabled: yes
        testing: yes
        recipient: [email protected]

        [mta]
        smtp_port: 9025
        lmtp_port: 9024
        incoming: mailman.testing.mta.FakeMTA

        [webservice]
        port: 9001

        [archiver.mhonarc]
        enable: yes

        [archiver.mail_archive]
        enable: yes

        [archiver.prototype]
        enable: yes
        """.format(var_dir, postfix_cfg))
        config.create_paths = True
        config.push('test config', test_config)
        # Initialize everything else.
    initialize.initialize_2(testing=True)
    initialize.initialize_3()

    config_file = os.path.join(var_dir, 'test.cfg')
    with open(config_file, 'w') as fp:
        fp.write(test_config)
        print(file=fp)
        config.filename = config_file
    # Start the Mailman's test runner.
    server = TestableMaster(wait_for_webservice)
    server.start('rest', 'in')
    request.addfinalizer(server.stop)
    # Run the test.
    yield
    reset_the_world()
    # Destroy the test database after the tests are done so that there is
    # no data in case the tests are rerun with a database layer like mysql
    # or postgresql which are not deleted in teardown.
    shutil.rmtree(var_dir)
    # Prevent the bit of post-processing on the .pop() that creates
    # directories.  We're basically shutting down everything and we don't
    # need the directories created.  Plus, doing so leaves a var directory
    # turd in the source tree's top-level directory.  We do it this way
    # rather than shutil.rmtree'ing the resulting var directory because
    # it's possible the user created a valid such directory for
    # operational or test purposes.
    config.create_paths = False
    config.pop('test config')
示例#32
0
 def tearDown(self):
     # Free references.
     del _deliveries[:]
     shutil.rmtree(self._template_dir)
     config.pop('templates')
示例#33
0
 def tearDown(self):
     if self.fp is not None:
         self.fp.close()
     config.pop('template config')
     shutil.rmtree(self.var_dir)
示例#34
0
 def tearDown(self):
     shutil.rmtree(self._tempdir)
     config.pop('prototype')
示例#35
0
 def tearDown(self):
     config.pop('dummy')
示例#36
0
 def tearDown(self):
     # Free references.
     del _deliveries[:]
     shutil.rmtree(self._template_dir)
     config.pop('templates')
示例#37
0
 def tearDown(self):
     config.pop('site owner')
示例#38
0
 def tearDown(self):
     config.pop('fake outgoing')
示例#39
0
 def tearDown(self):
     config.pop('xx template dir')
     shutil.rmtree(self._var_dir)
示例#40
0
 def tearDown(self):
     config.pop('dummy')
示例#41
0
 def tearDown(self):
     config.pop('template config')
     shutil.rmtree(self.var_dir)
示例#42
0
 def tearDown(self):
     config.pop('test config')