This commit is contained in:
Jean-Marie Place 2021-11-09 08:21:52 +01:00
parent 7fc8782e1d
commit f6e63624e0
9 changed files with 38 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -7,7 +7,7 @@ Utiliser comme:
pytest tests/unit/test_departements.py
"""
from shutil import copytree, copy
from shutil import copytree, copy, rmtree
from flask import g
import app
@ -43,21 +43,54 @@ def setup():
copy(f"{RESOURCES_DIR}/logo_F.jpeg", scu.SCODOC_LOGOS_DIR)
copytree(
f"{RESOURCES_DIR}/logos_1",
f"{scu.SCODOC_LOGOS_DIR}/logos_{d1}",
f"{scu.SCODOC_LOGOS_DIR}/logos_{d1.id}",
dirs_exist_ok=True,
)
copytree(
f"{RESOURCES_DIR}/logos_2",
f"{scu.SCODOC_LOGOS_DIR}/logos_{d2}",
f"{scu.SCODOC_LOGOS_DIR}/logos_{d2.id}",
dirs_exist_ok=True,
)
return d1, d2
def test_find_global_only(test_client):
"""find a global (only) logo"""
def tear_off(d1, d2):
db.session.delete(d1)
db.session.delete(d2)
db.session.commit()
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{d1.id}")
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{d2.id}")
copy(f"{RESOURCES_DIR}/logo_A.jpg", scu.SCODOC_LOGOS_DIR)
copy(f"{RESOURCES_DIR}/logo_C.jpg", scu.SCODOC_LOGOS_DIR)
copy(f"{RESOURCES_DIR}/logo_D.png", scu.SCODOC_LOGOS_DIR)
copy(f"{RESOURCES_DIR}/logo_E.jpg", scu.SCODOC_LOGOS_DIR)
copy(f"{RESOURCES_DIR}/logo_F.jpeg", scu.SCODOC_LOGOS_DIR)
copytree(
f"{RESOURCES_DIR}/logos_2",
f"{scu.SCODOC_LOGOS_DIR}/logos_{d2.id}",
dirs_exist_ok=True,
)
def test_find(test_client):
# find a global (only) logo
dept1, dept2 = setup()
d1 = dept1.id
d2 = dept2.id
C_logo = app.scodoc.sco_logos.find_logo(logoname="C")
assert C_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logo_C.jpg"
# find a local (only) logo
B_logo = app.scodoc.sco_logos.find_logo(logoname="B", dept_id=d1)
assert B_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{d1}/logo_B.jpg"
# find a local (preferred) logo
A1_logo = app.scodoc.sco_logos.find_logo(logoname="A", dept_id=d1)
assert A1_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{d1}/logo_A.jpg"
# find a global (strict) logo
A_logo = app.scodoc.sco_logos.find_logo(logoname="A", dept_id=None, strict=True)
assert A_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{d1}/logo_A.jpg"
# search for a local non-existant logo returns None
A2_logo = app.scodoc.sco_logos.find_logo(logoname="A", dept_id=d1, strict=True)
assert A2_logo.filepath is None
# bye
tear_off(dept1, dept2)