create MakeOrVerifyCoreDirTest

This commit is contained in:
Brad Warren 2016-07-08 14:54:51 -07:00
parent d777221703
commit e598e907bd

View file

@ -1,4 +1,5 @@
"""Tests for certbot.main."""
import os
import shutil
import tempfile
import unittest
@ -66,5 +67,30 @@ class SetupLogFileHandlerTest(unittest.TestCase):
self.config, "test.log", "%s")
class MakeOrVerifyCoreDirTest(unittest.TestCase):
"""Tests for certbot.main.make_or_verify_core_dir."""
def setUp(self):
self.dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.dir)
def _call(self, *args, **kwargs):
from certbot.main import make_or_verify_core_dir
return make_or_verify_core_dir(*args, **kwargs)
def test_success(self):
new_dir = os.path.join(self.dir, 'new')
self._call(new_dir, 0o700, os.geteuid(), False)
self.assertTrue(os.path.exists(new_dir))
@mock.patch('certbot.main.util.make_or_verify_dir')
def test_failure(self, mock_make_or_verify):
mock_make_or_verify.side_effect = OSError
self.assertRaises(errors.Error, self._call,
self.dir, 0o700, os.geteuid(), False)
if __name__ == '__main__':
unittest.main() # pragma: no cover