Skip to content

Commit

Permalink
Merge pull request #373 from nichtsfrei/master
Browse files Browse the repository at this point in the history
Allow running unittests as root
  • Loading branch information
jjnicola authored Jan 25, 2021
2 parents 31534a0 + 2bd4862 commit 62317c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def test_sudo_available(self, mock_openvas):

w = DummyDaemon()
w._sudo_available = None # pylint: disable=protected-access
w.sudo_available # pylint: disable=pointless-statement
w._is_running_as_root = False # pylint: disable=protected-access

self.assertTrue(w.sudo_available)

Expand Down
20 changes: 12 additions & 8 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import tempfile
import fcntl

from pathlib import Path
from pathlib import Path, PosixPath

from unittest.mock import patch, MagicMock
from ospd_openvas.lock import LockFile
Expand All @@ -36,7 +36,7 @@ def tearDown(self):
shutil.rmtree(str(self.temp_dir))

def test_acquire_lock(self):
lock_file_path = self.temp_dir / 'test.lock'
lock_file_path = self.temp_dir / "test.lock"

lock_file = LockFile(lock_file_path)
lock_file._acquire_lock()
Expand All @@ -45,9 +45,9 @@ def test_acquire_lock(self):
self.assertTrue(lock_file_path.exists())
lock_file._release_lock()

@patch('ospd_openvas.lock.logger')
@patch("ospd_openvas.lock.logger")
def test_already_locked(self, mock_logger):
lock_file_path = self.temp_dir / 'test.lock'
lock_file_path = self.temp_dir / "test.lock"

lock_file_aux = LockFile(lock_file_path)
lock_file_aux._acquire_lock()
Expand All @@ -61,7 +61,7 @@ def test_already_locked(self, mock_logger):
lock_file_aux._release_lock()

def test_create_parent_dirs(self):
lock_file_path = self.temp_dir / 'foo' / 'bar' / 'test.lock'
lock_file_path = self.temp_dir / "foo" / "bar" / "test.lock"

lock_file = LockFile(lock_file_path)
lock_file._acquire_lock()
Expand All @@ -74,9 +74,13 @@ def test_create_parent_dirs(self):

lock_file._release_lock()

@patch('ospd_openvas.lock.logger')
@patch("ospd_openvas.lock.logger")
def test_create_paren_dirs_fail(self, mock_logger):
lock_file_path = Path('/root/lock/file/test.lock')
lock_file_path = MagicMock(spec=Path).return_value
parent = MagicMock(spec=PosixPath)
lock_file_path.parent = parent
parent.mkdir.side_effect = PermissionError

lock_file = LockFile(lock_file_path)

lock_file._acquire_lock()
Expand All @@ -85,7 +89,7 @@ def test_create_paren_dirs_fail(self, mock_logger):
assert_called_once(mock_logger.error)

def test_context_manager(self):
lock_file_path = self.temp_dir / 'test.lock'
lock_file_path = self.temp_dir / "test.lock"

lock_file = LockFile(lock_file_path)

Expand Down

0 comments on commit 62317c8

Please sign in to comment.