forked from ScoDoc/ScoDoc
adapt tests for new spacs
This commit is contained in:
parent
7fdb4c3cb6
commit
2f4be9b949
|
@ -46,7 +46,7 @@ from app import Departement, ScoValueError
|
|||
from app.scodoc import sco_utils as scu
|
||||
from PIL import Image as PILImage
|
||||
|
||||
GLOBAL = "_GLOBAL" # category for server level logos
|
||||
GLOBAL = "_" # category for server level logos
|
||||
|
||||
|
||||
def find_logo(logoname, dept_id=None, strict=False, prefix=scu.LOGO_FILE_PREFIX):
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 2.7 KiB |
BIN
tests/ressources/test_logos/logo_A1.jpg
Normal file
BIN
tests/ressources/test_logos/logo_A1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
tests/ressources/test_logos/logos_2/logo_A1.jpg
Normal file
BIN
tests/ressources/test_logos/logos_2/logo_A1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
|
@ -7,7 +7,6 @@ Utiliser comme:
|
|||
pytest tests/unit/test_logos.py
|
||||
|
||||
"""
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from shutil import copytree, copy, rmtree
|
||||
|
||||
|
@ -18,7 +17,7 @@ import app
|
|||
from app import db
|
||||
from app.models import Departement
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.scodoc.sco_logos import find_logo, Logo, list_logos
|
||||
from app.scodoc.sco_logos import find_logo, Logo, list_logos, GLOBAL, write_logo
|
||||
|
||||
RESOURCES_DIR = "/opt/scodoc/tests/ressources/test_logos"
|
||||
|
||||
|
@ -30,12 +29,15 @@ def create_dept(test_client):
|
|||
"""
|
||||
dept1 = Departement(acronym="RT")
|
||||
dept2 = Departement(acronym="INFO")
|
||||
dept3 = Departement(acronym="GEA")
|
||||
db.session.add(dept1)
|
||||
db.session.add(dept2)
|
||||
db.session.add(dept3)
|
||||
db.session.commit()
|
||||
yield dept1, dept2
|
||||
yield dept1, dept2, dept3
|
||||
db.session.delete(dept1)
|
||||
db.session.delete(dept2)
|
||||
db.session.delete(dept3)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
@ -52,9 +54,10 @@ def create_logos(create_dept):
|
|||
+-- logos_{d2} --+-- logo_A.jpg
|
||||
|
||||
"""
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
d1 = dept1.id
|
||||
d2 = dept2.id
|
||||
d3 = dept3.id
|
||||
FILE_LIST = ["logo_A.jpg", "logo_C.jpg", "logo_D.png", "logo_E.jpg", "logo_F.jpeg"]
|
||||
for fn in FILE_LIST:
|
||||
from_path = Path(RESOURCES_DIR).joinpath(fn)
|
||||
|
@ -83,33 +86,33 @@ def test_select_global_only(create_logos):
|
|||
|
||||
|
||||
def test_select_local_only(create_dept, create_logos):
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
B_logo = app.scodoc.sco_logos.find_logo(logoname="B", dept_id=dept1.id)
|
||||
assert B_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1.id}/logo_B.jpg"
|
||||
|
||||
|
||||
def test_select_local_override_global(create_dept, create_logos):
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
A1_logo = app.scodoc.sco_logos.find_logo(logoname="A", dept_id=dept1.id)
|
||||
assert A1_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1.id}/logo_A.jpg"
|
||||
|
||||
|
||||
def test_select_global_with_strict(create_dept, create_logos):
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
A_logo = app.scodoc.sco_logos.find_logo(logoname="A", dept_id=dept1.id, strict=True)
|
||||
assert A_logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1.id}/logo_A.jpg"
|
||||
|
||||
|
||||
def test_looks_for_non_existant_should_give_none(create_dept, create_logos):
|
||||
# search for a local non-existant logo returns None
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
no_logo = app.scodoc.sco_logos.find_logo(logoname="Z", dept_id=dept1.id)
|
||||
assert no_logo is None
|
||||
|
||||
|
||||
def test_looks_localy_for_a_global_should_give_none(create_dept, create_logos):
|
||||
# search for a local non-existant logo returns None
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
no_logo = app.scodoc.sco_logos.find_logo(
|
||||
logoname="C", dept_id=dept1.id, strict=True
|
||||
)
|
||||
|
@ -123,8 +126,8 @@ def test_get_jpg_data(create_dept, create_logos):
|
|||
assert logo.logoname == "A"
|
||||
assert logo.suffix == "jpg"
|
||||
assert logo.filename == "A.jpg"
|
||||
assert logo.size == (1200, 600)
|
||||
assert logo.mm == approx((40, 30), 0.1)
|
||||
assert logo.size == (140, 121)
|
||||
assert logo.mm == approx((5.74, 4.96), 0.1)
|
||||
|
||||
|
||||
def test_get_png_without_data(create_dept, create_logos):
|
||||
|
@ -141,8 +144,23 @@ def test_get_png_without_data(create_dept, create_logos):
|
|||
|
||||
def test_create_globale_jpg_logo(create_dept, create_logos):
|
||||
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
|
||||
logo = Logo("X") # create global logo
|
||||
stream = path.open("rb")
|
||||
logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_X.jpg")
|
||||
assert not logo_path.exists()
|
||||
write_logo(stream, name="X") # create global logo
|
||||
assert logo_path.exists()
|
||||
logo_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_create_locale_jpg_logo(create_dept, create_logos):
|
||||
dept1, dept2, dept3 = create_dept
|
||||
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
|
||||
stream = path.open("rb")
|
||||
logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_Y.jpg")
|
||||
assert not logo_path.exists()
|
||||
write_logo(stream, name="Y", dept_id=dept1.id) # create global logo
|
||||
assert logo_path.exists()
|
||||
logo_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_create_jpg_instead_of_png_logo(create_dept, create_logos):
|
||||
|
@ -169,15 +187,17 @@ def test_create_jpg_instead_of_png_logo(create_dept, create_logos):
|
|||
|
||||
def test_list_logo(create_dept, create_logos):
|
||||
# test only existence of copied logos. We assumes that they are OK
|
||||
dept1, dept2 = create_dept
|
||||
dept1, dept2, dept3 = create_dept
|
||||
logos = list_logos()
|
||||
assert logos.keys() == {"_GLOBAL", "RT", "INFO"}
|
||||
assert set(logos.keys()) == { dept1.id, dept2.id, None }
|
||||
assert {"A", "C", "D", "E", "F", "header", "footer"}.issubset(
|
||||
set(logos["_GLOBAL"].keys())
|
||||
set(logos[None].keys())
|
||||
)
|
||||
rt = logos.get("RT", None)
|
||||
rt = logos.get(dept1.id, None)
|
||||
assert rt is not None
|
||||
assert {"A", "B"}.issubset(set(rt.keys()))
|
||||
info = logos.get("INFO", None)
|
||||
info = logos.get(dept2.id, None)
|
||||
assert info is not None
|
||||
assert {"A"}.issubset(set(rt.keys()))
|
||||
gea = logos.get(dept3.id, None)
|
||||
assert gea is None
|
||||
|
|
Loading…
Reference in New Issue
Block a user