ScodocTestClient/03_etudiant_test.py

189 lines
6.9 KiB
Python
Raw Permalink Normal View History

2021-04-21 13:28:58 +02:00
import unittest
import time
2021-05-27 16:36:42 +02:00
import subprocess
2021-05-28 20:41:04 +02:00
from setting import (
2021-05-27 16:36:42 +02:00
SCODOC_ADMIN_ID,
SCODOC_ADMIN_PASS,
BASE_URL,
NOM_DPT,
LINK_SCODOC_SERVER,
BASE_NOT_SECURED_URL,
NAVIGATEUR,
2021-05-27 16:36:42 +02:00
)
2021-04-21 13:28:58 +02:00
import urllib.parse as urlparse
from urllib.parse import parse_qs
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
2021-05-27 16:36:42 +02:00
from selenium.common.exceptions import NoSuchElementException
2021-04-21 13:28:58 +02:00
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support.select import Select
2021-05-27 16:36:42 +02:00
URL = BASE_URL + NOM_DPT + "/Scolarite"
nomEtu = "Semestre11"
prenomEtu = "Etudiant1"
2021-04-21 13:28:58 +02:00
nip = "11122234"
domicile = "50 rue de la marmite"
codepostaldomicile = "59000"
paysdomicile = "Lille"
class PythonOrgSearch(unittest.TestCase):
# Permet de se connecter et se remettre sur la page d'accueil avant chaque test
def setUp(self):
if NAVIGATEUR == "firefox":
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Chrome()
2021-04-21 13:28:58 +02:00
self.wait = WebDriverWait(self.driver, 10)
self.driver.get(
"https://"
+ SCODOC_ADMIN_ID
+ ":"
+ SCODOC_ADMIN_PASS
2021-05-27 16:36:42 +02:00
+ "@"
+ BASE_NOT_SECURED_URL
+ "force_admin_authentication"
2021-04-21 13:28:58 +02:00
)
2021-05-27 16:36:42 +02:00
global URL
self.driver.get(URL)
2021-04-21 13:28:58 +02:00
# Test : creer un etudiant et verifie si sa fiche etudiante est creee
2021-05-06 08:32:30 +02:00
# @expected : A la soumission du formulaire on retrouve la fiche d'information avec le nip (unique) dans la page, on a également un resultat en recherchant l'étudiant
2021-05-06 20:28:22 +02:00
def test_01_creation_etudiant(self):
2021-04-21 13:28:58 +02:00
driver = self.driver
2021-05-27 16:36:42 +02:00
global URL
driver.find_element_by_id("link_create_etudident").click()
self.wait.until(EC.url_changes(URL))
URL = driver.current_url
2021-04-21 13:28:58 +02:00
driver.find_element_by_id("tf_nom").send_keys(nomEtu)
driver.find_element_by_id("tf_prenom").send_keys(prenomEtu)
driver.find_element_by_id("tf_annee").send_keys("2021")
driver.find_element_by_id("tf_code_nip").send_keys(nip)
driver.find_element_by_name("dont_check_homonyms:list").click()
driver.find_element_by_id("tf_submit").click()
time.sleep(1)
self.assertTrue("M. " + prenomEtu + " " + nomEtu.upper() in driver.page_source)
self.assertTrue(nip in driver.page_source)
2021-05-06 08:32:30 +02:00
# Test : Creer un étudiant avec un nip qui est déjà présent dans la base Scodoc
# @expected : La création mène à une page qui affiche "code étudiant dupliqué", l'étudiant n'est pas créé
2021-05-06 20:28:22 +02:00
def test_02_creation_etudiant_avec_meme_nip(self):
2021-04-21 13:28:58 +02:00
driver = self.driver
2021-05-27 16:36:42 +02:00
global URL
driver.get(URL)
2021-04-21 13:28:58 +02:00
driver.find_element_by_id("tf_nom").send_keys(nomEtu)
driver.find_element_by_id("tf_prenom").send_keys(prenomEtu)
driver.find_element_by_id("tf_annee").send_keys("2021")
driver.find_element_by_id("tf_code_nip").send_keys(nip)
driver.find_element_by_name("dont_check_homonyms:list").click()
driver.find_element_by_id("tf_submit").click()
time.sleep(1)
self.assertTrue(
2021-05-06 20:28:22 +02:00
"Code étudiant (code_nip) dupliqué !"
in driver.find_element_by_id("titleError").text
2021-04-21 13:28:58 +02:00
)
2021-05-06 08:32:30 +02:00
# Test Modification de l'adresse étudiant
# expected : La nouvelle adresse est mise à jour sur la page information de l'étudiant
2021-05-06 20:28:22 +02:00
def test_03_modification_adresse_etudiant(self):
2021-04-21 13:28:58 +02:00
driver = self.driver
2021-05-27 16:36:42 +02:00
global URL
driver.get(URL)
element = driver.find_element_by_id("in-expnom")
2021-04-21 13:28:58 +02:00
element.send_keys(nomEtu)
element.submit()
2021-05-27 16:36:42 +02:00
self.wait.until(EC.url_changes(URL))
driver.find_element_by_xpath(
"//a[contains(@href,'formChangeCoordonnees')]"
).click()
2021-04-21 13:28:58 +02:00
time.sleep(1)
driver.find_element_by_id("tf_domicile").send_keys(domicile)
driver.find_element_by_id("tf_codepostaldomicile").send_keys(codepostaldomicile)
driver.find_element_by_id("tf_paysdomicile").send_keys(paysdomicile)
driver.find_element_by_id("tf_submit").click()
2021-04-23 13:57:24 +02:00
time.sleep(1)
2021-05-06 20:28:22 +02:00
self.assertTrue(
2021-05-27 16:36:42 +02:00
codepostaldomicile in driver.find_element_by_id("adresse_etudiant").text
2021-05-06 20:28:22 +02:00
)
2021-04-21 13:28:58 +02:00
2021-05-06 08:32:30 +02:00
# Test Inscription d'un étudiant dans un semestre
# @expected :
2021-05-06 20:28:22 +02:00
def test_04_inscription_etudiant(self):
2021-04-21 13:28:58 +02:00
driver = self.driver
2021-05-27 16:36:42 +02:00
global URL
driver.get(URL)
element = driver.find_element_by_id("in-expnom")
2021-04-21 13:28:58 +02:00
element.send_keys(nomEtu)
element.submit()
2021-05-27 16:36:42 +02:00
self.wait.until(EC.url_changes(URL))
driver.find_element_by_xpath(
"//a[contains(@href, 'formsemestre_inscription_with_modules_form')]"
).click()
self.wait.until(EC.url_changes(URL))
try:
semestres = driver.find_elements_by_xpath(
"//a[contains(@id,'inscription_Semestre_')]"
)
except NoSuchElementException:
self.assertFalse(True)
semestres[0].click()
2021-04-21 13:28:58 +02:00
driver.find_element_by_xpath("//input[@value='Inscrire']").click()
2021-05-27 16:36:42 +02:00
self.assertTrue("inscrit" in driver.page_source)
2021-04-23 13:57:24 +02:00
time.sleep(1)
2021-04-21 13:28:58 +02:00
2021-05-06 08:32:30 +02:00
# Test Supprime un étudiant
# @expected : Lors d'une recherche sur le nom de l'étudiant, aucun résultat apparait
2021-05-06 20:28:22 +02:00
def test_05_suppresion_etudiant(self):
2021-04-21 13:28:58 +02:00
driver = self.driver
2021-04-23 13:57:24 +02:00
urlRecherche = (
2021-04-21 13:28:58 +02:00
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
2021-05-27 16:36:42 +02:00
+ NOM_DPT
2021-04-21 13:28:58 +02:00
+ "/Scolarite/search_etud_in_dept"
)
2021-04-23 13:57:24 +02:00
driver.get(urlRecherche)
2021-04-21 13:28:58 +02:00
element = driver.find_element_by_name("expnom")
element.send_keys(nomEtu)
element.submit()
time.sleep(1)
etudid = driver.find_element_by_id("euid")
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
2021-05-27 16:36:42 +02:00
+ NOM_DPT
2021-04-23 13:57:24 +02:00
+ "/Scolarite/etudident_delete?etudid="
2021-04-21 13:28:58 +02:00
+ etudid.text
)
driver.get(url)
2021-04-23 13:57:24 +02:00
time.sleep(1)
2021-04-21 13:28:58 +02:00
driver.find_element_by_xpath(
"//input[@value='Supprimer définitivement cet étudiant']"
).click()
2021-04-23 13:57:24 +02:00
driver.get(urlRecherche)
element = driver.find_element_by_name("expnom")
element.send_keys(nomEtu)
element.submit()
time.sleep(1)
2021-05-06 20:28:22 +02:00
try:
element = driver.find_element_by_id("titleNoResult")
self.assertTrue("Aucun résultat" in element.text)
except:
self.assertFalse(False)
2021-04-21 13:28:58 +02:00
# ferme la fenetre
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, NOM_DPT]
process = subprocess.Popen(cmdProcess)
process.wait()
cmdProcess = [
"./scriptExecution.sh",
LINK_SCODOC_SERVER,
NOM_DPT,
"test_scenario1_formation.py",
]
process = subprocess.Popen(cmdProcess)
process.wait()
2021-04-21 13:28:58 +02:00
unittest.main()