delete logo now may delete several files & tests

This commit is contained in:
Jean-Marie Place 2021-12-02 16:47:45 +01:00
parent ee5b610da4
commit 958e96dce9
2 changed files with 35 additions and 4 deletions

View File

@ -71,9 +71,15 @@ def find_logo(logoname, dept_id=None, strict=False, prefix=scu.LOGO_FILE_PREFIX)
def delete_logo(name, dept_id=None):
logo = find_logo(logoname=name, dept_id=dept_id).select()
if logo is not None:
os.unlink(logo.filepath)
"""Delete all files matching logo (dept_id, name) (including all allowed extensions)
Args:
name: The name of the logo
dept_id: the dept_id (if local). Use None to destroy globals logos
"""
logo = find_logo(logoname=name, dept_id=dept_id)
while logo is not None:
os.unlink(logo.select().filepath)
logo = find_logo(logoname=name, dept_id=dept_id)
def write_logo(stream, name, dept_id=None):

View File

@ -149,7 +149,7 @@ def test_get_png_without_data(create_dept, create_logos):
assert logo.mm is None
def test_delete_global_jpg_logo(create_dept, create_logos):
def test_delete_unique_global_jpg_logo(create_dept, create_logos):
from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_W.jpg")
copy(from_path.absolute(), to_path.absolute())
@ -158,6 +158,31 @@ def test_delete_global_jpg_logo(create_dept, create_logos):
assert not to_path.exists()
def test_delete_unique_local_jpg_logo(create_dept, create_logos):
dept1, dept2, dept3 = create_dept
from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_W.jpg")
copy(from_path.absolute(), to_path.absolute())
assert to_path.exists()
delete_logo(name="W", dept_id=dept1.id)
assert not to_path.exists()
def test_delete_multiple_local_jpg_logo(create_dept, create_logos):
dept1, dept2, dept3 = create_dept
from_path_A = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
to_path_A = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.jpg")
from_path_B = Path(RESOURCES_DIR).joinpath("logo_D.png")
to_path_B = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.png")
copy(from_path_A.absolute(), to_path_A.absolute())
copy(from_path_B.absolute(), to_path_B.absolute())
assert to_path_A.exists()
assert to_path_B.exists()
delete_logo(name="V", dept_id=dept1.id)
assert not to_path_A.exists()
assert not to_path_B.exists()
def test_create_global_jpg_logo(create_dept, create_logos):
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
stream = path.open("rb")