mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 04:46:18 -05:00
Refresh files removed files that were deleted.
This commit is contained in:
parent
22f603e567
commit
812369fdb3
4 changed files with 49 additions and 2 deletions
|
|
@ -1,9 +1,12 @@
|
|||
from pathlib import Path
|
||||
from typing import List, Iterable
|
||||
|
||||
import pytest
|
||||
|
||||
from modules.files import lib
|
||||
from modules.files.models import File
|
||||
from wrolpi.errors import InvalidFile
|
||||
from wrolpi.media_path import MediaPathType
|
||||
|
||||
|
||||
def test_list_files(make_files_structure, test_directory):
|
||||
|
|
@ -137,3 +140,32 @@ def test_delete_file(make_files_structure, test_directory):
|
|||
)
|
||||
def test_split_file_name(path, expected):
|
||||
assert lib.split_file_name(Path(path)) == expected
|
||||
|
||||
|
||||
def test_refresh_files(test_session, make_files_structure, test_directory):
|
||||
files = make_files_structure([
|
||||
'foo.txt',
|
||||
'bar.txt',
|
||||
'baz.txt',
|
||||
])
|
||||
foo, bar, baz = files
|
||||
|
||||
def get_relative_strs(files_: Iterable[MediaPathType]) -> List[str]:
|
||||
return sorted([str(i.path.path.relative_to(test_directory)) for i in files_])
|
||||
|
||||
lib.refresh_files()
|
||||
results = test_session.query(File)
|
||||
assert get_relative_strs(results) == ['bar.txt', 'baz.txt', 'foo.txt']
|
||||
|
||||
baz.unlink()
|
||||
|
||||
lib.refresh_files()
|
||||
results = test_session.query(File)
|
||||
assert get_relative_strs(results) == ['bar.txt', 'foo.txt']
|
||||
|
||||
foo.unlink()
|
||||
bar.unlink()
|
||||
|
||||
lib.refresh_files()
|
||||
results = test_session.query(File)
|
||||
assert get_relative_strs(results) == []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue