ScodocTestClient/etudiant_test.py

164 lines
5.9 KiB
Python
Raw Normal View History

2021-04-21 13:28:58 +02:00
import unittest
import time
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
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support.select import Select
SCODOC_ADMIN_ID = "admin"
SCODOC_ADMIN_PASS = "root_pass_42"
nomDPT = "AurelienUS"
nomEtu = "UnAutreEtudiant"
prenomEtu = "Normal"
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):
self.driver = webdriver.Firefox()
self.wait = WebDriverWait(self.driver, 10)
self.driver.get(
"https://"
+ SCODOC_ADMIN_ID
+ ":"
+ SCODOC_ADMIN_PASS
+ "@scodoc-dev-iutinfo.univ-lille.fr/force_admin_authentication"
)
self.driver.get("https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc")
# Test : creer un etudiant et verifie si sa fiche etudiante est creee
def test_creation_etudiant(self):
driver = self.driver
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
+ nomDPT
+ "/Scolarite/etudident_create_form"
)
driver.get(url)
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)
def test_creation_etudiant_avec_meme_nip(self):
driver = self.driver
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
+ nomDPT
+ "/Scolarite/etudident_create_form"
)
driver.get(url)
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(
"<h3>Code étudiant (code_nip) dupliqué !</h3>" in driver.page_source
)
def test_modification_adresse_etudiant(self):
driver = self.driver
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
+ nomDPT
+ "/Scolarite/search_etud_in_dept"
)
driver.get(url)
element = driver.find_element_by_name("expnom")
element.send_keys(nomEtu)
element.submit()
time.sleep(1)
driver.find_element_by_link_text("modifier adresse").click()
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()
time.sleep(5)
self.assertTrue(
codepostaldomicile + " " + paysdomicile + " " + paysdomicile
in driver.page_source
)
def test_inscription_etudiant(self):
driver = self.driver
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
+ nomDPT
+ "/Scolarite/search_etud_in_dept"
)
driver.get(url)
element = driver.find_element_by_name("expnom")
element.send_keys(nomEtu)
element.submit()
time.sleep(1)
driver.find_element_by_link_text("inscrire").click()
time.sleep(1)
self.assertTrue("<h3>Choisir un semestre:</h3>" in driver.page_source)
driver.find_elements_by_id("semestreInscription")[0].click()
self.wait.until(EC.url_changes(url))
driver.find_element_by_xpath("//input[@value='Inscrire']").click()
self.wait.until(EC.url_changes(url))
time.sleep(5)
self.assertTrue("Inscrire" not in driver.page_source)
def test_suppresion_etudiant(self):
driver = self.driver
url = (
"https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"
+ nomDPT
+ "/Scolarite/search_etud_in_dept"
)
driver.get(url)
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/"
+ nomDPT
+ "etudident_delete?etudid="
+ etudid.text
)
driver.get(url)
time.sleep(2)
driver.find_element_by_xpath(
"//input[@value='Supprimer définitivement cet étudiant']"
).click()
# Test changer les donnees d'un etudiant
# ferme la fenetre
def tearDown(self):
# url = "https://scodoc-dev-iutinfo.univ-lille.fr/ScoDoc/"+nomDPT+"/Scolarite/"
# self.driver.get(url)
# elem = self.driver.find_element_by_id("in-expnom")
# elem.send_keys(nomEtu)
# elem.send_keys(Keys.ENTER)
# self.wait.until(EC.url_changes(url))
# url = self.driver.current_url
# parsedurl = urlparse.urlparse(url)
# etudi = parse_qs(parsedurl)['etudid']
# print(etudi)
# self.driver.get(url+"etidodent_delete?etutid="+etudi)
self.driver.close()
if __name__ == "__main__":
unittest.main()