forked from ScoDoc/DocScoDoc
New fake Apo portal for tests
This commit is contained in:
parent
5e24cd8100
commit
2e45d63529
1
tests/demo/__init__.py
Normal file
1
tests/demo/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Demo package
|
@ -15,6 +15,8 @@ import sys
|
||||
import random
|
||||
import psycopg2
|
||||
|
||||
from gen_nomprenoms import nomprenom
|
||||
|
||||
|
||||
def usage():
|
||||
print(f"Usage: {sys.argv[0]} dbname formsemestre_id")
|
||||
@ -28,21 +30,6 @@ dbname = sys.argv[1]
|
||||
formsemestre_id = sys.argv[2]
|
||||
DBCNXSTRING = f"dbname={dbname}"
|
||||
|
||||
# Noms et prénoms les plus fréquents en France:
|
||||
NOMS = [x.strip() for x in open("noms.txt").readlines()]
|
||||
PRENOMS_H = [x.strip() for x in open("prenoms-h.txt").readlines()]
|
||||
PRENOMS_F = [x.strip() for x in open("prenoms-f.txt").readlines()]
|
||||
|
||||
|
||||
def nomprenom(sexe):
|
||||
"""un nom et un prenom au hasard"""
|
||||
if "e" in sexe.lower():
|
||||
prenom = random.choice(PRENOMS_F)
|
||||
else:
|
||||
prenom = random.choice(PRENOMS_H)
|
||||
return random.choice(NOMS), prenom
|
||||
|
||||
|
||||
# Liste des etudiants inscrits à ce semestre
|
||||
cnx = psycopg2.connect(DBCNXSTRING)
|
||||
cursor = cnx.cursor()
|
||||
|
21
tests/demo/gen_nomprenoms.py
Normal file
21
tests/demo/gen_nomprenoms.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
cur_dir = Path(os.path.abspath(__file__)).parent
|
||||
|
||||
# Noms et prénoms les plus fréquents en France:
|
||||
NOMS = [x.strip() for x in open(cur_dir / "noms.txt").readlines()]
|
||||
PRENOMS_H = [x.strip() for x in open(cur_dir / "prenoms-h.txt").readlines()]
|
||||
PRENOMS_F = [x.strip() for x in open(cur_dir / "prenoms-f.txt").readlines()]
|
||||
|
||||
|
||||
def nomprenom(sexe):
|
||||
"""un nom et un prenom au hasard"""
|
||||
if "e" in sexe.lower() or "f" in sexe.lower():
|
||||
prenom = random.choice(PRENOMS_F)
|
||||
else:
|
||||
prenom = random.choice(PRENOMS_H)
|
||||
return random.choice(NOMS), prenom
|
17
tests/fakeportal/etapes.xml
Normal file
17
tests/fakeportal/etapes.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<etapes>
|
||||
<etape code="V1RT">DUT RESEAUX ET TELECOMMUNICATIONS an1</etape>
|
||||
<etape code="V2RT">DUT Reseaux et Telecommunications an2</etape>
|
||||
<etape code="V2RT2">DUT Réseaux et Télécommunications an2 (AP)</etape>
|
||||
<etape code="VCLS1A">Certificat de Competences en Anglais niveau 1</etape>
|
||||
<etape code="VCZ1C">PERIODE DE CESURE 1ER CYCLE IUT VILLETANEUSE</etape>
|
||||
<etape code="VUEIL">DIU Enseigner l'informatique au lycee</etape>
|
||||
<etape code="VUSDA">DU SCALA DATA ANALYST</etape>
|
||||
<etape code="VUTGPI">DU Techniques & gestion de projets en ingenierie ferroviaire</etape>
|
||||
<etape code="VXVI">AUDITEUR LIBRE A L'IUT DE VILLETANEUSE</etape>
|
||||
<etape code="V1CII">Certficat informatique et internet niv 1</etape>
|
||||
<etape code="V1CJ">DUT CARRIERES JURIDIQUES an1</etape>
|
||||
<etape code="V1CJ1">DUT CARRIERES JURIDIQUES an1 (CP)</etape>
|
||||
<etape code="V1CJ2">DUT CARRIERES JURIDIQUES an1 (AP)</etape>
|
||||
<etape code="V1CJ4">DUT CARRIERES JURIDIQUES (FCTP) an1</etape>
|
||||
</etapes>
|
12
tests/fakeportal/etud_minimal_template.xml
Normal file
12
tests/fakeportal/etud_minimal_template.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<etudiant>
|
||||
<nip>{nip}</nip>
|
||||
<etape>{etape}</etape>
|
||||
<gender>{gender}</gender>
|
||||
<nom>{nom}</nom>
|
||||
<nomusuel></nomusuel>
|
||||
<prenom>{prenom}</prenom>
|
||||
<fullname>{prenom} {nom}</fullname>
|
||||
<naissance>23/08/2001</naissance>
|
||||
<inscription>{annee}</inscription>
|
||||
<mail>{prenom}.martin@edu.sco.zzz</mail>
|
||||
</etudiant>
|
38
tests/fakeportal/etud_template.xml
Normal file
38
tests/fakeportal/etud_template.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<etudiant>
|
||||
<nip>{nip}</nip>
|
||||
<etape>{etape}</etape>
|
||||
<versionetape>{etape}/117</versionetape>
|
||||
<versiondiplome>{diplome}/117</versiondiplome>
|
||||
<gender>{gender}</gender>
|
||||
<nom>{nom}</nom>
|
||||
<nomusuel></nomusuel>
|
||||
<prenom>{prenom}</prenom>
|
||||
<naissance>23/08/2001</naissance>
|
||||
<inscription>{annee}</inscription>
|
||||
<address>11, rue Simon Crubellier</address>
|
||||
<postalcode>75017</postalcode>
|
||||
<city>PARIS</city>
|
||||
<country>FRANCE</country>
|
||||
<phone>0606060606</phone>
|
||||
<mail>{prenom}.martin@edu.sco.zzz</mail>
|
||||
<bac>S Scientifique</bac>
|
||||
<anneebac>2019</anneebac>
|
||||
<lycee>07981234T</lycee>
|
||||
<mention>AB</mention>
|
||||
<bourse>N</bourse>
|
||||
<paiementinscription>true</paiementinscription>
|
||||
<datefinalisationinscription></datefinalisationinscription>
|
||||
<ville_naissance>MEAUX</ville_naissance>
|
||||
<code_dep_naissance>099</code_dep_naissance>
|
||||
<libelle_dep_naissance>Etranger</libelle_dep_naissance>
|
||||
<cod_stu>01</cod_stu>
|
||||
<cod_rgi>1</cod_rgi>
|
||||
<tem_brs_iaa>N</tem_brs_iaa>
|
||||
<eta_edt_crt></eta_edt_crt>
|
||||
<dat_edt_crt></dat_edt_crt>
|
||||
<cod_pru>NO</cod_pru>
|
||||
<cod_dip>{diplome}</cod_dip>
|
||||
<cod_etp>{etape}</cod_etp>
|
||||
<tem_rgl_sit_mil>O</tem_rgl_sit_mil>
|
||||
<fullname>{prenom} {nom}</fullname>
|
||||
</etudiant>
|
127
tests/fakeportal/fakeportal.py
Executable file
127
tests/fakeportal/fakeportal.py
Executable file
@ -0,0 +1,127 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
"""Simple fake HTTP serveur
|
||||
emulating "Apogee" Web service
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import random
|
||||
import time
|
||||
import http.server
|
||||
import socketserver
|
||||
from urllib.parse import urlparse
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
sys.path.append("..")
|
||||
from demo.gen_nomprenoms import nomprenom
|
||||
|
||||
# Etudiant avec tous les champs (USPN)
|
||||
ETUD_TEMPLATE_FULL = open("etud_template.xml").read()
|
||||
# Etudiant avec seulement les champs requis
|
||||
ETUD_TEMPLATE_MINI = open("etud_minimal_template.xml").read()
|
||||
|
||||
ETUD_HEAD = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<etudiants>"""
|
||||
ETUD_TAIL = """</etudiants>
|
||||
"""
|
||||
|
||||
|
||||
def make_random_etud(nip, etape=None, annee=None, template=ETUD_TEMPLATE_FULL):
|
||||
"""return XML for a student"""
|
||||
random.seed(nip) # deterministic choice based on nip
|
||||
gender = random.choice(("M", "F"))
|
||||
nom, prenom = nomprenom(gender)
|
||||
if not etape:
|
||||
etape = random.choice(("V1RT", "V2RT", "V2RT2", ""))
|
||||
if not annee:
|
||||
annee = time.strftime("%Y") # current year
|
||||
diplome = "VDRT"
|
||||
data = template.format(
|
||||
nip=nip,
|
||||
gender=gender,
|
||||
nom=nom,
|
||||
prenom=prenom,
|
||||
etape=etape,
|
||||
diplome=diplome,
|
||||
annee=annee,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
def make_random_etape_etuds(etape, annee):
|
||||
"""Liste d'etudiants d'une etape"""
|
||||
random.seed(etape + annee)
|
||||
nb = random.randint(0, 50)
|
||||
L = []
|
||||
for i in range(nb):
|
||||
if i % 2:
|
||||
template = ETUD_TEMPLATE_MINI
|
||||
else:
|
||||
template = ETUD_TEMPLATE_FULL
|
||||
nip = str(random.randint(10000000, 99999999)) # 8 digits
|
||||
L.append(make_random_etud(nip, etape=etape, annee=annee, template=template))
|
||||
return "\n".join(L)
|
||||
|
||||
|
||||
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def send_xml(self, data):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/xml;charset=UTF-8")
|
||||
self.end_headers()
|
||||
self.wfile.write(bytes(data, "utf8"))
|
||||
|
||||
def do_GET(self):
|
||||
query_components = parse_qs(urlparse(self.path).query)
|
||||
print(f"path={self.path}", file=sys.stderr)
|
||||
print(query_components, file=sys.stderr)
|
||||
|
||||
if "etapes" in self.path.lower():
|
||||
self.path = "etapes.xml"
|
||||
elif "scodocEtudiant" in self.path:
|
||||
# 2 forms: nip=xxx or etape=eee&annee=aaa
|
||||
if "nip" in query_components:
|
||||
nip = query_components["nip"][0]
|
||||
print(f"requesting nip={nip}")
|
||||
data = ETUD_HEAD + make_random_etud(nip) + ETUD_TAIL
|
||||
return self.send_xml(data)
|
||||
elif "etape" in query_components:
|
||||
etape = query_components["etape"][0]
|
||||
print(f"requesting etape={etape}")
|
||||
if "annee" in query_components:
|
||||
annee = query_components["annee"][0]
|
||||
data = ETUD_HEAD + make_random_etape_etuds(etape, annee) + ETUD_TAIL
|
||||
return self.send_xml(data)
|
||||
else:
|
||||
print(
|
||||
f"Error 404: (missing annee) path={self.path}", file=sys.stderr
|
||||
)
|
||||
self.send_response(404)
|
||||
return
|
||||
else:
|
||||
print(
|
||||
f"Error 404: (missing nip or etape) path={self.path}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
self.send_response(404)
|
||||
return
|
||||
else:
|
||||
print(f"Error 404: path={self.path}")
|
||||
self.send_response(404)
|
||||
return
|
||||
|
||||
# Sending an '200 OK' response
|
||||
self.send_response(200)
|
||||
http.server.SimpleHTTPRequestHandler.do_GET(self)
|
||||
|
||||
return
|
||||
|
||||
|
||||
# Create an object of the above class
|
||||
handler_object = MyHttpRequestHandler
|
||||
|
||||
PORT = 8678
|
||||
my_server = socketserver.TCPServer(("", PORT), handler_object)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Start the server
|
||||
my_server.serve_forever()
|
Loading…
Reference in New Issue
Block a user