From ddae09278e1e990ad62c052c27c1d17849da4d09 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 1 Oct 2021 12:44:05 +0300 Subject: [PATCH] Refactor test_data_store_encryptor.py to use (path / to / file).isfile() syntax to check for presence of files --- .../encryption/test_data_store_encryptor.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py index ef4ee20d0..1a394c025 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_data_store_encryptor.py @@ -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()