UT: Update tests as per changes to file repositories

This commit is contained in:
Shreya Malviya 2022-09-28 19:39:16 +05:30
parent 7823759cf8
commit 64990eea0e
3 changed files with 6 additions and 5 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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"}