コード例 #1
0
ファイル: base.py プロジェクト: ColdrickSotK/storyboard
    def enabled(self):
        """Indicate whether the email plugin system is enabled. It checks for
        all the necessary configuration options that are required.
        """

        # Assert that the configuration is set to enabled.
        email_config = CONF.plugin_email
        if not email_config.enable:
            return False

        # Assert that we can generate a working directory.
        try:
            get_email_directory()
        except IOError as e:
            LOG.error('Cannot create working directory, disabling plugin: %s' %
                      (e,))
            return False

        # Assert that the smtp sender can connect to the server.
        try:
            with get_smtp_client():
                pass
        except smtplib.SMTPException as e:
            LOG.error('Cannot contact SMTP server, disabling plugin: %s' %
                      (e,))
            return False

        # Looks like we have all we need.
        return True
コード例 #2
0
    def enabled(self):
        """Indicate whether the email plugin system is enabled. It checks for
        all the necessary configuration options that are required.
        """

        # Assert that the configuration is set to enabled.
        email_config = CONF.plugin_email
        if not email_config.enable:
            return False

        # Assert that we can generate a working directory.
        try:
            get_email_directory()
        except IOError as e:
            LOG.error('Cannot create working directory, disabling plugin: %s' %
                      (e, ))
            return False

        # Assert that the smtp sender can connect to the server.
        try:
            with get_smtp_client():
                pass
        except smtplib.SMTPException as e:
            LOG.error('Cannot contact SMTP server, disabling plugin: %s' %
                      (e, ))
            return False

        # Looks like we have all we need.
        return True
コード例 #3
0
ファイル: outbox.py プロジェクト: devcurmudgeon/storyboard
    def __init__(self):
        """Create a new instance of our outbox."""
        working_directory = get_email_directory()
        outbox_path = os.path.join(working_directory, 'outbox')

        # Explicitly set the factory to None, because py2.7 defaults this to
        # rfc822, which causes the return types to be different between 3.4
        # and 2.7.
        mailbox.Maildir.__init__(self, outbox_path, factory=None)
コード例 #4
0
ファイル: test_init.py プロジェクト: vladiskuz/storyboard
    def test_get_email_directory(self):
        """Can we resolve the email directory? Most of this testing also
        exists in test_working_dir, however it behooves us to test it here as
        well.
        """
        expected_path = os.path.realpath(os.path.join(CONF.working_directory,
                                                      'plugin', 'email'))
        self.assertFalse(os.path.exists(expected_path))

        resolved_path = get_email_directory()

        self.assertEqual(expected_path, resolved_path)
        self.assertTrue(os.path.exists(CONF.working_directory))
        self.assertTrue(os.path.exists(expected_path))

        self.assertTrue(os.access(CONF.working_directory, os.W_OK))
        self.assertTrue(os.access(expected_path, os.W_OK))
コード例 #5
0
    def test_get_email_directory(self):
        """Can we resolve the email directory? Most of this testing also
        exists in test_working_dir, however it behooves us to test it here as
        well.
        """
        expected_path = os.path.realpath(os.path.join(CONF.working_directory,
                                                      'plugin', 'email'))
        self.assertFalse(os.path.exists(expected_path))

        resolved_path = get_email_directory()

        self.assertEqual(expected_path, resolved_path)
        self.assertTrue(os.path.exists(CONF.working_directory))
        self.assertTrue(os.path.exists(expected_path))

        self.assertTrue(os.access(CONF.working_directory, os.W_OK))
        self.assertTrue(os.access(expected_path, os.W_OK))
コード例 #6
0
ファイル: test_base.py プロジェクト: devcurmudgeon/storyboard
    def setup_helper(self, config=True, working_dir=True, outbox=True,
                     smtp=True):
        """Setup helper: Setup the email test environment with various items
        enabled/disabled.
        """
        CONF.set_override('enable', config, 'plugin_email')

        if not working_dir:
            os.chmod(CONF.working_directory, PERM_READ_ONLY)
        elif not outbox:
            # Can't modify this if the parent directory's already locked down.
            email = get_email_directory()
            os.chmod(email, PERM_READ_ONLY)

        if not smtp:
            mock.DummySMTP.exception = smtplib.SMTPException

        self.addCleanup(self._clear_setup)