From 4df1bdda8e3adc74bff659905d5f50b967c11dfb Mon Sep 17 00:00:00 2001 From: iziram Date: Tue, 20 Dec 2022 20:02:26 +0100 Subject: [PATCH] =?UTF-8?q?tests=20unitaires=20Mod=C3=A8le=20+=20MAJ=20fic?= =?UTF-8?q?hier=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._ajout_modeles_assiduites_justificatifs.py | 86 ++++++++++++------- tests/unit/test_assiduites.py | 40 +++++++++ tests/unit/test_but_ues.py | 8 +- 3 files changed, 104 insertions(+), 30 deletions(-) diff --git a/migrations/versions/530594458193_ajout_modeles_assiduites_justificatifs.py b/migrations/versions/530594458193_ajout_modeles_assiduites_justificatifs.py index 53a849f7a..fb36c80cb 100644 --- a/migrations/versions/530594458193_ajout_modeles_assiduites_justificatifs.py +++ b/migrations/versions/530594458193_ajout_modeles_assiduites_justificatifs.py @@ -1,7 +1,7 @@ """Ajout Modeles Assiduites Justificatifs Revision ID: 530594458193 -Revises: f95656fdd3ef +Revises: 3c12f5850cff Create Date: 2022-12-19 13:56:28.597632 """ @@ -10,45 +10,73 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '530594458193' -down_revision = 'f95656fdd3ef' +revision = "530594458193" +down_revision = "3c12f5850cff" branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('justificatifs', - sa.Column('justifid', sa.Integer(), nullable=False), - sa.Column('date_debut', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('date_fin', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('etudid', sa.Integer(), nullable=False), - sa.Column('etat', sa.Integer(), nullable=True), - sa.Column('raison', sa.Text(), nullable=True), - sa.Column('fichier', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['etudid'], ['identite.id'], ondelete='CASCADE'), - sa.PrimaryKeyConstraint('justifid') + op.create_table( + "justificatifs", + sa.Column("justifid", sa.Integer(), nullable=False), + sa.Column( + "date_debut", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=False, + ), + sa.Column( + "date_fin", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=False, + ), + sa.Column("etudid", sa.Integer(), nullable=False), + sa.Column("etat", sa.Integer(), nullable=True), + sa.Column("raison", sa.Text(), nullable=True), + sa.Column("fichier", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(["etudid"], ["identite.id"], ondelete="CASCADE"), + sa.PrimaryKeyConstraint("justifid"), ) - op.create_index(op.f('ix_justificatifs_etudid'), 'justificatifs', ['etudid'], unique=False) - op.create_table('assiduites', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('date_debut', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('date_fin', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('moduleimpl_id', sa.Integer(), nullable=True), - sa.Column('etudid', sa.Integer(), nullable=False), - sa.Column('etat', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['etudid'], ['identite.id'], ondelete='CASCADE'), - sa.ForeignKeyConstraint(['moduleimpl_id'], ['notes_moduleimpl.id'], ondelete='SET NULL'), - sa.PrimaryKeyConstraint('id') + op.create_index( + op.f("ix_justificatifs_etudid"), "justificatifs", ["etudid"], unique=False + ) + op.create_table( + "assiduites", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column( + "date_debut", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=False, + ), + sa.Column( + "date_fin", + sa.DateTime(timezone=True), + server_default=sa.text("now()"), + nullable=False, + ), + sa.Column("moduleimpl_id", sa.Integer(), nullable=True), + sa.Column("etudid", sa.Integer(), nullable=False), + sa.Column("etat", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(["etudid"], ["identite.id"], ondelete="CASCADE"), + sa.ForeignKeyConstraint( + ["moduleimpl_id"], ["notes_moduleimpl.id"], ondelete="SET NULL" + ), + sa.PrimaryKeyConstraint("id"), + ) + op.create_index( + op.f("ix_assiduites_etudid"), "assiduites", ["etudid"], unique=False ) - op.create_index(op.f('ix_assiduites_etudid'), 'assiduites', ['etudid'], unique=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_assiduites_etudid'), table_name='assiduites') - op.drop_table('assiduites') - op.drop_index(op.f('ix_justificatifs_etudid'), table_name='justificatifs') - op.drop_table('justificatifs') + op.drop_index(op.f("ix_assiduites_etudid"), table_name="assiduites") + op.drop_table("assiduites") + op.drop_index(op.f("ix_justificatifs_etudid"), table_name="justificatifs") + op.drop_table("justificatifs") # ### end Alembic commands ### diff --git a/tests/unit/test_assiduites.py b/tests/unit/test_assiduites.py index 1242b5276..1bb5b6641 100644 --- a/tests/unit/test_assiduites.py +++ b/tests/unit/test_assiduites.py @@ -10,6 +10,8 @@ Ecrit par HARTMANN Matthias (en s'inspirant de tests.unit.test_abs_count.py par from tests.unit import sco_fake_gen +from app import db + from app.scodoc import sco_formsemestre import app.scodoc.sco_assiduites as scass from app.models import Assiduite, Identite, FormSemestre @@ -102,6 +104,44 @@ def test_general(test_client): verifier_comptage_et_filtrage( etuds, moduleimpls, (formsemestre_1, formsemestre_2, formsemestre_3) ) + editer_supprimer_assiduiter(etuds, moduleimpls) + + +def editer_supprimer_assiduiter(etuds: list[Identite], moduleimpls: list[int]): + """ + Troisième Partie: + - Vérification de l'édition des assiduitées + - Vérification de la suppression des assiduitées + """ + + from sqlalchemy.exc import IntegrityError + + ass1: Assiduite = etuds[0].assiduites.first() + ass2: Assiduite = etuds[1].assiduites.first() + ass3: Assiduite = etuds[2].assiduites.first() + + # Modification de l'état + ass1.etat = scu.EtatAssiduite.RETARD + db.session.add(ass1) + # Modification du moduleimpl + ass2.moduleimpl_id = moduleimpls[0] + db.session.add(ass2) + db.session.commit() + + # Vérification du changement + assert ( + scass.filter_by_etat(etuds[0].assiduites, "retard").count() == 3 + ), "Edition d'assiduité mauvais" + assert ( + scass.filter_by_module_impl(etuds[1].assiduites, moduleimpls[0]).count() == 2 + ), "Edition d'assiduité mauvais" + + # Supression d'une assiduité + + db.session.delete(ass3) + db.session.commit() + + assert etuds[2].assiduites.count() == 5, "Supression d'assiduité mauvais" def ajouter_assiduites(etuds: list[Identite], moduleimpls: list[int]): diff --git a/tests/unit/test_but_ues.py b/tests/unit/test_but_ues.py index 64a109587..3c38a6e7e 100644 --- a/tests/unit/test_but_ues.py +++ b/tests/unit/test_but_ues.py @@ -123,7 +123,13 @@ def test_ue_moy(test_client): modimpl.module.ue.type != UE_SPORT for modimpl in formsemestre.modimpls_sorted ] etud_moy_ue = moy_ue.compute_ue_moys_apc( - sem_cube, etuds, modimpls, modimpl_inscr_df, modimpl_coefs_df, modimpl_mask + sem_cube, + etuds, + modimpls, + modimpl_inscr_df, + modimpl_coefs_df, + modimpl_mask, + set(), ) assert etud_moy_ue[ue1.id][etudid] == n1 assert etud_moy_ue[ue2.id][etudid] == n1