forked from p15670423/monkey
Refactor test_data_store_encryptor.py to use (path / to / file).isfile() syntax to check for presence of files
This commit is contained in:
parent
4cbed6dce9
commit
ddae09278e
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from tests.unit_tests.monkey_island.cc.conftest import MOCK_PASSWORD, MOCK_USERNAME
|
||||
|
||||
|
@ -34,23 +32,23 @@ def initialized_key_dir(tmpdir):
|
|||
|
||||
|
||||
def test_key_creation(initialized_key_dir):
|
||||
assert os.path.isfile(os.path.join(initialized_key_dir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert (initialized_key_dir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
|
||||
|
||||
def test_key_removal_fails_if_key_initialized(initialized_key_dir):
|
||||
remove_old_datastore_key()
|
||||
assert os.path.isfile(os.path.join(initialized_key_dir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert (initialized_key_dir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
|
||||
|
||||
def test_key_removal(initialized_key_dir, monkeypatch):
|
||||
monkeypatch.setattr(DataStoreEncryptor, "is_key_setup", lambda _: False)
|
||||
remove_old_datastore_key()
|
||||
assert not os.path.isfile(os.path.join(initialized_key_dir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert not (initialized_key_dir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
|
||||
|
||||
def test_key_removal__no_key(tmpdir):
|
||||
initialize_datastore_encryptor(tmpdir)
|
||||
assert not os.path.isfile(os.path.join(tmpdir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert not (tmpdir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
# Make sure no error thrown when we try to remove an non-existing key
|
||||
remove_old_datastore_key()
|
||||
|
||||
|
@ -65,7 +63,7 @@ def test_encryptor_not_initialized():
|
|||
|
||||
def test_setup_datastore_key(tmpdir):
|
||||
initialize_datastore_encryptor(tmpdir)
|
||||
assert not os.path.isfile(os.path.join(tmpdir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert not (tmpdir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
setup_datastore_key(MOCK_USERNAME, MOCK_PASSWORD)
|
||||
assert os.path.isfile(os.path.join(tmpdir, DataStoreEncryptor._KEY_FILENAME))
|
||||
assert (tmpdir / DataStoreEncryptor._KEY_FILENAME).isfile()
|
||||
assert get_datastore_encryptor().is_key_setup()
|
||||
|
|
Loading…
Reference in New Issue