From 64990eea0e04f4dbe077e1c24c0cef187bd1d906 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 28 Sep 2022 19:39:16 +0530 Subject: [PATCH] UT: Update tests as per changes to file repositories --- monkey/tests/monkey_island/mock_file_repository.py | 2 +- monkey/tests/monkey_island/single_file_repository.py | 4 ++-- .../cc/repository/test_local_storage_file_repository.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/monkey/tests/monkey_island/mock_file_repository.py b/monkey/tests/monkey_island/mock_file_repository.py index f828cdd5a..e7dc76bc1 100644 --- a/monkey/tests/monkey_island/mock_file_repository.py +++ b/monkey/tests/monkey_island/mock_file_repository.py @@ -24,7 +24,7 @@ class MockFileRepository(IFileRepository): def delete_file(self, unsafe_file_name: str): pass - def delete_files_by_pattern(self, file_name_pattern: str): + def delete_files_by_regex(self, file_name_regex: str): pass def delete_all_files(self): diff --git a/monkey/tests/monkey_island/single_file_repository.py b/monkey/tests/monkey_island/single_file_repository.py index 66086f0f2..be9f896ba 100644 --- a/monkey/tests/monkey_island/single_file_repository.py +++ b/monkey/tests/monkey_island/single_file_repository.py @@ -24,8 +24,8 @@ class SingleFileRepository(IFileRepository): self._file = None self._file_name = "" - def delete_files_by_pattern(self, file_name_pattern: str): - if re.match(file_name_pattern, self._file_name): + def delete_files_by_regex(self, file_name_regex: re.Pattern): + if re.match(file_name_regex, self._file_name): self.delete_file("") def delete_all_files(self): diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py index 03fa1f5ca..f088ee16e 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py @@ -1,4 +1,5 @@ import io +import re from pathlib import Path from unittest.mock import Mock, patch @@ -145,12 +146,12 @@ def test_open_locked_file(tmp_path, monkeypatch): fss.open_file("locked_file.txt") -def test_delete_files_by_pattern(tmp_path): +def test_delete_files_by_regex(tmp_path): for filename in {"xyz-1.txt", "abc-2.txt", "pqr-3.txt", "abc-4.txt", "abc-5.pdf"}: (tmp_path / filename).touch() fss = LocalStorageFileRepository(tmp_path) - fss.delete_files_by_pattern("abc-*.txt") + fss.delete_files_by_regex(re.compile(r"^abc-[\w-]+.txt$")) files = {f.name for f in tmp_path.iterdir()} assert files == {"xyz-1.txt", "pqr-3.txt", "abc-5.pdf"}