ScoDoc/tests/unit/test_refcomp.py

37 lines
1.0 KiB
Python
Raw Permalink Normal View History

2021-12-02 12:08:03 +01:00
"""Test models referentiel compétences
Utiliser par exemple comme:
pytest tests/unit/test_refcomp.py
"""
import io
from flask import g
import app
from app import db
2021-12-03 14:13:49 +01:00
from app import models
2021-12-02 12:08:03 +01:00
from app.but.import_refcomp import orebut_import_refcomp
from app.models.but_refcomp import (
ApcReferentielCompetences,
ApcCompetence,
ApcSituationPro,
)
def test_but_refcomp(test_client):
"""modèles ref. comp."""
2021-12-03 14:13:49 +01:00
xml_data = open("tests/data/but-RT-refcomp-exemple.xml").read()
dept_id = models.Departement.query.first().id
ref = orebut_import_refcomp(xml_data, dept_id)
assert ref.competences.count() == 13
assert ref.competences[0].situations.count() == 3
2021-12-02 12:08:03 +01:00
assert ref.competences[0].situations[0].libelle.startswith("Conception ")
2021-12-03 14:13:49 +01:00
assert (
ref.competences[-1].situations[-1].libelle
== "Administration des services multimédia"
)
2021-12-02 12:08:03 +01:00
# test cascades on delete
db.session.delete(ref)
db.session.commit()
assert ApcCompetence.query.count() == 0
assert ApcSituationPro.query.count() == 0