ScoDoc-PE/tests/unit/test_refcomp.py

56 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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
from app.but.import_refcomp import orebut_import_refcomp
from app.models.but_refcomp import (
ApcReferentielCompetences,
ApcCompetence,
ApcSituationPro,
)
ref_xml = """<?xml version="1.0" encoding="UTF-8"?>
<referentiel_competence specialite="RT" specialite_long="Réseaux et télécommunications" type="B.U.T.">
<competences>
<competence name="Administrer" numero="1" libelle_long="Administrer les réseaux et lInternet"
couleur="c1">
<situations>
<situation>Conception et administration de linfrastructure du réseau informatique dune entreprise</situation>
<situation>Installation et administration des services réseau informatique dune entreprise</situation>
</situations>
</competence>
<competence name="Tester" numero="2" libelle_long="Tester...">
<situations>
<situation>
Tests unitaires d'une application.
</situation>
</situations>
</competence>
</competences>
<parcours>
<parcour>
</parcour>
</parcours>
</referentiel_competence>
"""
def test_but_refcomp(test_client):
"""modèles ref. comp."""
f = io.StringIO(ref_xml)
ref = orebut_import_refcomp(f)
assert ref.references.count() == 2
assert ref.competences[0].situations.count() == 2
assert ref.competences[0].situations[0].libelle.startswith("Conception ")
# test cascades on delete
db.session.delete(ref)
db.session.commit()
assert ApcCompetence.query.count() == 0
assert ApcSituationPro.query.count() == 0