Merge "Email Working Directory Utility Method"
This commit is contained in:
commit
545b49262c
@ -15,6 +15,9 @@
|
||||
from oslo.config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from storyboard.common.working_dir import get_plugin_directory
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -62,3 +65,11 @@ PLUGIN_OPTS = [
|
||||
]
|
||||
|
||||
CONF.register_opts(PLUGIN_OPTS, "plugin_email")
|
||||
|
||||
|
||||
def get_email_directory():
|
||||
"""A shared utility method that always provides the same working
|
||||
directory. Error handling is explicitly not provided, as the methods used
|
||||
'should' be consistent about the errors they themselves raise.
|
||||
"""
|
||||
return get_plugin_directory("email")
|
||||
|
@ -12,15 +12,19 @@
|
||||
# implied. See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import stat
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from storyboard.plugin.email import get_email_directory
|
||||
from storyboard.tests import base
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestConfiguration(base.TestCase):
|
||||
class TestEmailConfiguration(base.TestCase):
|
||||
def test_configuration_defaults(self):
|
||||
self.assertIsNotNone(CONF.plugin_email)
|
||||
|
||||
@ -34,3 +38,35 @@ class TestConfiguration(base.TestCase):
|
||||
self.assertEqual(None, conf.smtp_ssl_certfile)
|
||||
self.assertEqual(None, conf.smtp_user)
|
||||
self.assertEqual(None, conf.smtp_password)
|
||||
|
||||
|
||||
class TestGetEmailDirectory(base.WorkingDirTestCase):
|
||||
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))
|
||||
|
||||
def test_get_email_directory_not_creatable(self):
|
||||
"""Assert that the get_email_directory() method raises an error if
|
||||
it cannot be created.
|
||||
"""
|
||||
|
||||
# Set the permissions
|
||||
os.chmod(CONF.working_directory,
|
||||
stat.S_IRUSR + stat.S_IRGRP + stat.S_IROTH)
|
||||
|
||||
# Make sure it raises an exception.
|
||||
self.assertRaises(IOError, get_email_directory)
|
||||
|
Loading…
x
Reference in New Issue
Block a user