Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 11
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
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 16
0
 def tearDown(self):
     config.pop('test config')
Ejemplo n.º 17
0
 def _remove(self):
     config.pop(self._uuid)
Ejemplo n.º 18
0
 def tearDown(self):
     config.pop('dispose')
Ejemplo n.º 19
0
 def tearDown(self):
     config.pop('password scheme')
     reset_the_world()
Ejemplo n.º 20
0
 def tearDown(self):
     config.pop('site owner')
Ejemplo n.º 21
0
 def tearDown(self):
     config.pop('no template dir')
     shutil.rmtree(self.var_dir)
Ejemplo n.º 22
0
 def _remove(self):
     config.pop(self._uuid)
Ejemplo n.º 23
0
 def tearDown(self):
     shutil.rmtree(self._tempdir)
     config.pop('prototype')
Ejemplo n.º 24
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
Ejemplo n.º 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
Ejemplo n.º 26
0
 def tearDown(cls):
     assert cls.smtpd is not None, 'Layer not set up'
     cls.smtpd.clear()
     cls.smtpd.stop()
     config.pop('starttls')
Ejemplo n.º 27
0
 def tearDown(self):
     config.pop('dispose')
Ejemplo n.º 28
0
 def tearDown(self):
     config.pop('fake outgoing')
Ejemplo n.º 29
0
 def tearDown(self):
     config.pop("template config")
     shutil.rmtree(self.var_dir)
Ejemplo n.º 30
0
 def tearDown(self):
     if self.fp is not None:
         self.fp.close()
     config.pop('template config')
     shutil.rmtree(self.var_dir)
Ejemplo n.º 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')
Ejemplo n.º 32
0
 def tearDown(self):
     # Free references.
     del _deliveries[:]
     shutil.rmtree(self._template_dir)
     config.pop('templates')
Ejemplo n.º 33
0
 def tearDown(self):
     if self.fp is not None:
         self.fp.close()
     config.pop('template config')
     shutil.rmtree(self.var_dir)
Ejemplo n.º 34
0
 def tearDown(self):
     shutil.rmtree(self._tempdir)
     config.pop('prototype')
Ejemplo n.º 35
0
 def tearDown(self):
     config.pop('dummy')
Ejemplo n.º 36
0
 def tearDown(self):
     # Free references.
     del _deliveries[:]
     shutil.rmtree(self._template_dir)
     config.pop('templates')
Ejemplo n.º 37
0
 def tearDown(self):
     config.pop('site owner')
Ejemplo n.º 38
0
 def tearDown(self):
     config.pop('fake outgoing')
Ejemplo n.º 39
0
 def tearDown(self):
     config.pop('xx template dir')
     shutil.rmtree(self._var_dir)
Ejemplo n.º 40
0
 def tearDown(self):
     config.pop('dummy')
Ejemplo n.º 41
0
 def tearDown(self):
     config.pop('template config')
     shutil.rmtree(self.var_dir)
Ejemplo n.º 42
0
 def tearDown(self):
     config.pop('test config')