forked from ScoDoc/DocScoDoc
143 lines
4.3 KiB
Python
143 lines
4.3 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Creation environnement pour test.
|
|
A utiliser avec debug.py (côté serveur).
|
|
"""
|
|
|
|
from __future__ import print_function
|
|
import sys
|
|
import string
|
|
import pprint
|
|
import random
|
|
|
|
random.seed(12345) # tests reproductibles
|
|
|
|
from debug import REQUEST
|
|
|
|
import sco_utils
|
|
from sco_exceptions import ScoValueError
|
|
import scolars
|
|
import sco_formsemestre_inscriptions
|
|
import sco_synchro_etuds
|
|
import sco_edit_formation
|
|
import sco_codes_parcours
|
|
from notes_log import log
|
|
|
|
DEMODIR = sco_utils.SCO_SRCDIR + "/scotests/demo/"
|
|
NOMS = [x.strip() for x in open(DEMODIR + "/noms.txt").readlines()]
|
|
PRENOMS_H = [x.strip() for x in open(DEMODIR + "/prenoms-h.txt").readlines()]
|
|
PRENOMS_F = [x.strip() for x in open(DEMODIR + "/prenoms-f.txt").readlines()]
|
|
# nb: en python2, les chaines ci-dessus sont en utf8
|
|
|
|
|
|
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
|
return "".join(random.choice(chars) for _ in range(size))
|
|
|
|
|
|
class ScoFake:
|
|
def __init__(self, context, verbose=True):
|
|
self.context = context
|
|
self.verbose = verbose
|
|
|
|
def log(self, msg):
|
|
if self.verbose:
|
|
print("ScoFake: " + str(msg), file=sys.stderr)
|
|
sys.stderr.flush()
|
|
log("ScoFake: " + str(msg))
|
|
|
|
def sexenomprenom(self):
|
|
"""un nom et un prenom au hasard,
|
|
toujours en majuscules.
|
|
"""
|
|
sexe = random.choice(("M", "F"))
|
|
if "e" in sexe.lower() or "f" in sexe.lower():
|
|
prenom = random.choice(PRENOMS_F)
|
|
else:
|
|
prenom = random.choice(PRENOMS_H)
|
|
return sexe, random.choice(NOMS).upper(), prenom.upper()
|
|
|
|
def create_etud(
|
|
self,
|
|
cnx=None,
|
|
code_nip="",
|
|
nom="",
|
|
prenom="",
|
|
code_ine="",
|
|
sexe="",
|
|
etape="TST1",
|
|
email="test@localhost",
|
|
emailperso="perso@localhost",
|
|
date_naissance="01/01/2001",
|
|
lieu_naissance="Paris",
|
|
dept_naissance="75",
|
|
domicile="1, rue du test",
|
|
codepostaldomicile="75123",
|
|
villedomicile="TestCity",
|
|
paysdomicile="France",
|
|
telephone="0102030405",
|
|
typeadresse="domicile",
|
|
boursier=None,
|
|
description="etudiant test",
|
|
):
|
|
"""Crée un étudiant"""
|
|
if not cnx:
|
|
cnx = self.context.GetDBConnexion()
|
|
if code_nip == "":
|
|
code_nip = str(random.randint(10000, 99999))
|
|
if not sexe or not nom or not prenom:
|
|
r_sexe, r_nom, r_prenom = self.sexenomprenom()
|
|
if not sexe:
|
|
sexe = r_sexe
|
|
if not nom:
|
|
nom = r_nom
|
|
if not prenom:
|
|
prenom = r_prenom
|
|
etud = scolars.create_etud(self.context, cnx, args=locals(), REQUEST=REQUEST)
|
|
pprint.pprint(etud)
|
|
self.log("create_etud( %s %s %s ) -> %s" % (sexe, prenom, nom, etud["etudid"]))
|
|
inscription = "2020"
|
|
sco_synchro_etuds.do_import_etud_admission(
|
|
self.context, cnx, etud["etudid"], locals()
|
|
)
|
|
return etud
|
|
|
|
def create_formation(
|
|
self,
|
|
acronyme="test",
|
|
titre="Formation test",
|
|
titre_officiel="Le titre officiel de la formation test",
|
|
type_parcours=sco_codes_parcours.ParcoursDUT.TYPE_PARCOURS,
|
|
formation_code=None,
|
|
code_specialite=None,
|
|
):
|
|
"""Crée une formation"""
|
|
if acronyme == "":
|
|
acronyme = "TEST" + str(random.randint(100000, 999999))
|
|
formation_id = self.context.do_formation_create(locals(), REQUEST=REQUEST)
|
|
Flist = self.context.formation_list(args={"formation_id": formation_id})
|
|
if not Flist:
|
|
raise ScoValueError("formation inexistante !")
|
|
self.log(
|
|
"create_formation( %s %s ) -> %s"
|
|
% (acronyme, titre, Flist[0]["formation_id"])
|
|
)
|
|
return Flist[0]
|
|
|
|
def create_ue(self):
|
|
pass
|
|
|
|
def create_fake_sem(self):
|
|
pass
|
|
|
|
def test_inscrit_etudiant(self, sem, etud):
|
|
sco_formsemestre_inscriptions.do_formsemestre_inscription_with_modules(
|
|
self.context,
|
|
sem["formsemestre_id"],
|
|
etud["etudid"],
|
|
etat="I",
|
|
etape=etud["etape"],
|
|
REQUEST=REQUEST,
|
|
method="test_inscrit_etudiant",
|
|
)
|