save a file to alocal folder and make it executable
This commit is contained in:
parent
e54626d971
commit
230cf99f06
8 changed files with 122 additions and 21 deletions
51
tests/local_files_test.py
Normal file
51
tests/local_files_test.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from pathlib import Path
|
||||
|
||||
from majordome import local_files
|
||||
|
||||
current_dir = Path(__file__).parent
|
||||
tmp_dir = current_dir / "tmp"
|
||||
|
||||
|
||||
def test_save_local_file(clean_tmpdir):
|
||||
file_content = b"some bytes"
|
||||
filename = "toto_titi.tutu"
|
||||
file_to_save = tmp_dir / filename
|
||||
tmp_files = list(tmp_dir.glob("*"))
|
||||
assert len(tmp_files) == 0
|
||||
|
||||
local_files.save(file_to_save, file_content)
|
||||
|
||||
tmp_files = list(tmp_dir.glob("*"))
|
||||
assert len(tmp_files) == 1
|
||||
tmp_file = tmp_files[0]
|
||||
assert tmp_file.name == filename
|
||||
assert tmp_file.read_bytes() == file_content
|
||||
|
||||
|
||||
def test_make_file_executable(clean_tmpdir):
|
||||
file = tmp_dir / "toto_titi.tutu"
|
||||
file.parent.mkdir(parents=True, exist_ok=True)
|
||||
file.touch()
|
||||
assert file.stat().st_mode == 0o100664
|
||||
|
||||
local_files.set_execution_rights(file)
|
||||
|
||||
assert file.stat().st_mode == 0o100775
|
||||
|
||||
|
||||
def test_download_and_make_executable(clean_tmpdir):
|
||||
file_content = b"some bytes"
|
||||
filename = "toto_titi.tutu"
|
||||
file_to_save = tmp_dir / filename
|
||||
tmp_files = list(tmp_dir.glob("*"))
|
||||
assert len(tmp_files) == 0
|
||||
|
||||
local_files.save_and_make_executable(file_to_save, file_content)
|
||||
|
||||
tmp_files = list(tmp_dir.glob("*"))
|
||||
assert len(tmp_files) == 1
|
||||
tmp_file = tmp_files[0]
|
||||
assert tmp_file.name == filename
|
||||
assert tmp_file.read_bytes() == file_content
|
||||
|
||||
assert tmp_file.stat().st_mode == 0o100775
|
Loading…
Add table
Add a link
Reference in a new issue