decompose fixtures

This commit is contained in:
Jean-Marie PLACE 2022-08-23 08:07:06 +02:00
parent fcb16a8af4
commit e91518c40d
2 changed files with 51 additions and 24 deletions

View File

@ -39,7 +39,48 @@ def create_dept(test_client):
@pytest.fixture
def create_logos(create_dept):
def copy_dept1(create_dept):
dept1, dept2, dept3 = create_dept
dept1_id = dept1.id
copytree(
f"{RESOURCES_DIR}/logos_1",
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}",
dirs_exist_ok=True,
)
yield dept1, dept2, dept3
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}")
@pytest.fixture
def copy_dept2(copy_dept1):
dept1, dept2, dept3 = copy_dept1
dept2_id = dept2.id
copytree(
f"{RESOURCES_DIR}/logos_2",
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}",
dirs_exist_ok=True,
)
yield dept1, dept2, dept3
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}")
@pytest.fixture
def copy_global(copy_dept2):
dept1, dept2, dept3 = copy_dept2
FILE_LIST = ["logo_A.jpg", "logo_C.jpg", "logo_D.png", "logo_E.jpg", "logo_F.jpeg"]
for filename in FILE_LIST:
from_path = Path(RESOURCES_DIR).joinpath(filename)
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename)
copy(from_path.absolute(), to_path.absolute())
yield dept1, dept2, dept3
# rm files
for filename in FILE_LIST:
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename)
to_path.unlink()
@pytest.fixture
def create_logos(copy_global):
"""Crée les logos:
...logos --+-- logo_A.jpg
+-- logo_C.jpg
@ -51,29 +92,8 @@ def create_logos(create_dept):
+-- logos_{d2} --+-- logo_A.jpg
"""
dept1, dept2, dept3 = create_dept
dept1_id = dept1.id
dept2_id = dept2.id
FILE_LIST = ["logo_A.jpg", "logo_C.jpg", "logo_D.png", "logo_E.jpg", "logo_F.jpeg"]
for filename in FILE_LIST:
from_path = Path(RESOURCES_DIR).joinpath(filename)
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename)
copy(from_path.absolute(), to_path.absolute())
copytree(
f"{RESOURCES_DIR}/logos_1",
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}",
)
copytree(
f"{RESOURCES_DIR}/logos_2",
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}",
)
dept1, dept2, dept3 = copy_global
yield dept1, dept2, dept3
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}")
rmtree(f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}")
# rm files
for filename in FILE_LIST:
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename)
to_path.unlink()
def get_token(user_name):

View File

@ -20,7 +20,14 @@ from app.scodoc.sco_logos import (
write_logo,
delete_logo,
)
from tests.unit.config_test_logos import create_dept, create_logos, RESOURCES_DIR
from tests.unit.config_test_logos import (
create_dept,
copy_dept1,
copy_dept2,
copy_global,
create_logos,
RESOURCES_DIR,
)
def test_select_global_only(create_logos):