mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 00:35:50 +02:00
Fix coverage for le_util
This commit is contained in:
@@ -17,6 +17,10 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
|
||||
:raises LetsEncryptClientError: if a directory already exists,
|
||||
but has wrong permissions or owner
|
||||
|
||||
:raises OSError: if invalid or inaccessible file names and
|
||||
paths, or other arguments that have the correct type,
|
||||
but are not accepted by the operating system.
|
||||
|
||||
"""
|
||||
try:
|
||||
os.makedirs(directory, mode)
|
||||
|
||||
@@ -4,6 +4,8 @@ import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
|
||||
class MakeOrVerifyDirTest(unittest.TestCase):
|
||||
"""Tests for letsencrypt.client.le_util.make_or_verify_dir.
|
||||
@@ -40,6 +42,11 @@ class MakeOrVerifyDirTest(unittest.TestCase):
|
||||
def test_existing_wrong_mode_fails(self):
|
||||
self.assertRaises(Exception, self._call, self.path, 0o600)
|
||||
|
||||
def test_reraises_os_error(self):
|
||||
with mock.patch.object(os, 'makedirs') as makedirs:
|
||||
makedirs.side_effect = OSError()
|
||||
self.assertRaises(OSError, self._call, 'bar', 12312312)
|
||||
|
||||
|
||||
class CheckPermissionsTest(unittest.TestCase):
|
||||
"""Tests for letsencrypt.client.le_util.check_permissions.
|
||||
@@ -86,6 +93,10 @@ class UniqueFileTest(unittest.TestCase):
|
||||
fd.close()
|
||||
self.assertEqual(open(name).read(), 'bar')
|
||||
|
||||
def test_right_mode(self):
|
||||
self.assertEqual(0o700, os.stat(self._call(0o700)[1]).st_mode & 0o777)
|
||||
self.assertEqual(0o100, os.stat(self._call(0o100)[1]).st_mode & 0o777)
|
||||
|
||||
def test_default_not_exists(self):
|
||||
self.assertEqual(self._call()[1], self.default_name)
|
||||
|
||||
@@ -168,6 +179,9 @@ class JOSEB64DecodeTest(unittest.TestCase):
|
||||
def test_non_ascii_unicode_fails(self):
|
||||
self.assertRaises(ValueError, self._call, u'\u0105')
|
||||
|
||||
def test_type_error_no_unicode_or_str(self):
|
||||
self.assertRaises(TypeError, self._call, object())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user