mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +02:00
create MakeOrVerifyCoreDirTest
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
"""Tests for certbot.main."""
|
"""Tests for certbot.main."""
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
@@ -66,5 +67,30 @@ class SetupLogFileHandlerTest(unittest.TestCase):
|
|||||||
self.config, "test.log", "%s")
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main() # pragma: no cover
|
unittest.main() # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user