From a5860ed5c0ba1f5b7a40cae97702186902bcae88 Mon Sep 17 00:00:00 2001 From: Nir Date: Wed, 19 Jun 2024 16:28:59 +0300 Subject: [PATCH] rewrote the test in more correct way --- tests/test_file_manager.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/test_file_manager.py b/tests/test_file_manager.py index ee147e8..d93a217 100644 --- a/tests/test_file_manager.py +++ b/tests/test_file_manager.py @@ -298,28 +298,38 @@ def test_file_manager_any_is_subfolder_of(): assert is_subfolder is False -def test_file_manager_is_allowed_path(): +def test_file_manager_is_allowed_path(setup_teardown): + scan_dir, reference_dir, move_to_dir, common_args = setup_teardown fm = FileManager(True).reset_all() - fm.add_protected_dir("C:\\Users\\user\\Desktop\\folder") - fm.add_protected_dir("C:\\Users\\user\\Desktop\\folder1") - fm.add_allowed_dir("C:\\Users\\user\\Desktop\\folder2") + + protected_dir1 = os.path.join(reference_dir, "folder") + protected_dir2 = os.path.join(reference_dir, "folder1") + allowed_dir = os.path.join(scan_dir, "folder2") + os.makedirs(protected_dir1) + os.makedirs(protected_dir2) + os.makedirs(allowed_dir) + os.makedirs(os.path.join(scan_dir, "folder3")) + + fm.add_protected_dir(os.path.join(reference_dir, "folder")) + fm.add_protected_dir(os.path.join(reference_dir, "folder1")) + fm.add_allowed_dir(os.path.join(scan_dir, "folder2")) # Test case 1: protected path - assert not fm.is_allowed_path("C:\\Users\\user\\Desktop\\folder\\subfolder") + assert not fm.is_allowed_path(os.path.join(reference_dir, "folder", "subfolder")) # Test case 2: protected path - assert not fm.is_allowed_path("C:\\Users\\user\\Desktop\\folder1\\subfolder") + assert not fm.is_allowed_path(os.path.join(reference_dir, "folder1", "subfolder")) # Test case 3: allowed path - assert fm.is_allowed_path("C:\\Users\\user\\Desktop\\folder2\\subfolder") + assert fm.is_allowed_path(os.path.join(scan_dir, "folder2", "subfolder")) # Test case 4: non-protected path - should be disallowed as allowed directories are set - assert not fm.is_allowed_path("C:\\Users\\user\\Desktop\\folder3\\subfolder") + assert not fm.is_allowed_path(os.path.join(scan_dir, "folder3", "subfolder")) fm = FileManager(True).reset_all() # Test case 5: no protected or allowed directories set - all paths should be allowed - assert fm.is_allowed_path("C:\\Users\\user\\Desktop\\folder3\\subfolder") - assert not fm.is_protected_path("C:\\Users\\user\\Desktop\\folder3\\subfolder") + assert fm.is_allowed_path(os.path.join(scan_dir, "folder3", "subfolder")) + assert not fm.is_protected_path(os.path.join(scan_dir, "folder3", "subfolder")) def test_python_source_files():