Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running unittests as root #373

Merged
merged 3 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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