From e9269992fe751164d8072f8459d1bbfd292d831f Mon Sep 17 00:00:00 2001 From: aurelien Date: Mon, 7 Jun 2021 16:48:11 +0200 Subject: [PATCH] refractoring, ajout de nouveaux test, correction de bug --- .envmodel | 3 +- 01_creation_departement_test.py | 6 +-- 02_creation_formation_test.py | 6 +-- 03_etudiant_test.py | 22 ++++---- 04_creation_absence_test.py | 28 +++++----- 05_saisie_note_test.py | 90 ++++++++++++++------------------ 06_test_moyenne.py | 87 +++++++++++++++++++++++++----- 07_test_admission.py | 0 UserStoryNew.yaml | 3 +- output.txt | 6 +++ readme.md | 2 +- setup.pyc | Bin 583 -> 0 bytes 12 files changed, 154 insertions(+), 99 deletions(-) create mode 100644 07_test_admission.py create mode 100644 output.txt delete mode 100644 setup.pyc diff --git a/.envmodel b/.envmodel index d03b431..15ce929 100644 --- a/.envmodel +++ b/.envmodel @@ -7,4 +7,5 @@ SCODOC_ENS_PASS = "enseignant_password" SCODOC_CHEF_ID = "chef_id" SCODOC_CHEF_PASS = "password" LINK_SCODOC_SERVER = "root@ssh_server_scodoc" -BASE_NOT_SECURED_URL = "scodoc-dev-iutinfo.univ-lille.fr/" \ No newline at end of file +BASE_NOT_SECURED_URL = "scodoc-dev-iutinfo.univ-lille.fr/" +NAVIGATEUR = "firefox" \ No newline at end of file diff --git a/01_creation_departement_test.py b/01_creation_departement_test.py index c2e07bf..5785951 100644 --- a/01_creation_departement_test.py +++ b/01_creation_departement_test.py @@ -18,9 +18,6 @@ from selenium.webdriver.support.select import Select class PythonOrgSearch(unittest.TestCase): - cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, "TESTCREATEDPT"] - process = subprocess.Popen(cmdProcess) - process.wait() # Permet de se connecter et se remettre sur la page d'accueil avant chaque test def setUp(self): if NAVIGATEUR == "firefox": @@ -82,4 +79,7 @@ class PythonOrgSearch(unittest.TestCase): if __name__ == "__main__": + cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, "TESTCREATEDPT"] + process = subprocess.Popen(cmdProcess) + process.wait() unittest.main() \ No newline at end of file diff --git a/02_creation_formation_test.py b/02_creation_formation_test.py index 66c62d6..5cbd09d 100644 --- a/02_creation_formation_test.py +++ b/02_creation_formation_test.py @@ -25,9 +25,6 @@ ACRONYME_FORMATION = "FormationTEST" class PythonOrgSearch(unittest.TestCase): - cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, NOM_DPT] - process = subprocess.Popen(cmdProcess) - process.wait() # Permet de se connecter et se remettre sur la page d'accueil avant chaque test def setUp(self): if NAVIGATEUR == "firefox": @@ -181,4 +178,7 @@ class PythonOrgSearch(unittest.TestCase): if __name__ == "__main__": + cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, NOM_DPT] + process = subprocess.Popen(cmdProcess) + process.wait() unittest.main() \ No newline at end of file diff --git a/03_etudiant_test.py b/03_etudiant_test.py index 159db70..20d996e 100644 --- a/03_etudiant_test.py +++ b/03_etudiant_test.py @@ -29,17 +29,6 @@ paysdomicile = "Lille" class PythonOrgSearch(unittest.TestCase): - 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() # Permet de se connecter et se remettre sur la page d'accueil avant chaque test def setUp(self): if NAVIGATEUR == "firefox": @@ -188,4 +177,15 @@ class PythonOrgSearch(unittest.TestCase): 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() unittest.main() \ No newline at end of file diff --git a/04_creation_absence_test.py b/04_creation_absence_test.py index 3440637..d80cdc8 100644 --- a/04_creation_absence_test.py +++ b/04_creation_absence_test.py @@ -22,21 +22,10 @@ URL = BASE_URL + NOM_DPT + "/Scolarite" NOM_ETU = "Semestre11" PRENOM_ETU = "EtudiantNumero1" dateDebutAbsenceNonJustifiee = "31/05/2021" -dateDebutAbsenceJustifiee = "30/05/2021" +dateDebutAbsenceJustifiee = "25/05/2021" class PythonOrgSearch(unittest.TestCase): - cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, NOM_DPT] - process = subprocess.Popen(cmdProcess) - process.wait() - cmdProcess = [ - "./scriptExecution.sh", - LINK_SCODOC_SERVER, - NOM_DPT, - "test_scenario2_formation.py", - ] - process = subprocess.Popen(cmdProcess) - process.wait() # Permet de se connecter et se remettre sur la page d'accueil avant chaque test def setUp(self): if NAVIGATEUR == "firefox": @@ -98,7 +87,7 @@ class PythonOrgSearch(unittest.TestCase): driver.find_element_by_name("datedebut").send_keys(dateDebutAbsenceJustifiee) driver.find_element_by_name("estjust").click() driver.find_element_by_id("butsubmit").submit() - self.wait.until(EC.url_changes(URL)) + time.sleep(1) self.assertTrue("Ajout de 2 absences justifiées" in driver.page_source) driver = self.driver driver.find_element_by_link_text("Liste").click() @@ -141,7 +130,7 @@ class PythonOrgSearch(unittest.TestCase): driver.find_element_by_xpath("//input[@value='Supprimer les absences']").click() self.wait.until(EC.url_changes(URL)) self.assertTrue("Annulation sur 2 demi-journées " in driver.page_source) - driver.find_element_by_id("supprimer_Absence ").click() + driver.find_element_by_id("supprimer_Absence").click() driver.find_element_by_name("datedebut").send_keys(dateDebutAbsenceNonJustifiee) driver.find_element_by_xpath("//input[@value='Supprimer les absences']").click() self.wait.until(EC.url_changes(URL)) @@ -161,4 +150,15 @@ class PythonOrgSearch(unittest.TestCase): 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_scenario2_formation.py", + ] + process = subprocess.Popen(cmdProcess) + process.wait() unittest.main() \ No newline at end of file diff --git a/05_saisie_note_test.py b/05_saisie_note_test.py index 0c23b94..e2caeb3 100644 --- a/05_saisie_note_test.py +++ b/05_saisie_note_test.py @@ -64,10 +64,6 @@ class PythonOrgSearch(unittest.TestCase): SCODOC_ENS_PASS ) self.driver.find_element_by_name("submit").click() - # self.driver.get(self.url) - # self.driver.find_element_by_id("name").send_keys(SCODOC_ENS_ID) - # self.driver.find_element_by_id("password").send_keys(SCODOC_ENS_PASS) - # self.driver.find_element_by_id("submit").click() # Test : Vérifie s'il y a un semestre en cours # @expected : La class listesems n'est pas vide et contient "Session en cours" @@ -96,49 +92,14 @@ class PythonOrgSearch(unittest.TestCase): except NoSuchElementException: self.assertFalse(False) - # Test : Ajout d'un enseignant comme résponsable d'un module - # @expected : Le nom de l'enseignant apparait désormais sur la page d'information du module - def test_030_ajout_enseignant_sur_module(self): + def test_030_changement_responsable_sur_module(self): driver = self.driver - # driver.get(BASE_URL) - # driver.find_element_by_link_text("déconnecter").click() - # driver.get(BASE_URL) - # driver.find_element_by_id("name").send_keys(SCODOC_CHEF_ID) - # driver.find_element_by_id("password").send_keys(SCODOC_CHEF_PASS) - # driver.find_element_by_id("submit").click() - # global URL_SEMESTRE + isThere = False driver.get(URL_SEMESTRE) driver.find_element_by_link_text("M4101C").click() time.sleep(1) global URL_MATIERE URL_MATIERE = driver.current_url - driver.find_element_by_partial_link_text("modifier les enseignants").click() - time.sleep(1) - constructIDEns = ( - SCODOC_ENS_ID.upper() + " " + PRENOM_ENS + " (" + SCODOC_ENS_ID + ")" - ) - driver.find_element_by_id("ens_id").send_keys(constructIDEns) - driver.find_element_by_id("tf_submit").click() - time.sleep(1) - driver.get(URL_MATIERE) - professeurDansModule = driver.find_elements_by_class_name("ens_Dans_Module") - # self.assertTrue("Enseignants du" in driver.page_source) - time.sleep(5) - professeurString = [] - for professeur in professeurDansModule: - professeurString.append(professeur.text) - for professeurS in professeurString: - print(SCODOC_ENS_ID.lower() + " " + professeurS.lower()) - print(professeurS.lower().find(SCODOC_ENS_ID.lower() + " e.")) - if professeurS.lower().find(SCODOC_ENS_ID.lower() + " e."): - self.assertTrue(True) - - self.assertFalse(True) - - def test_031_changement_responsable_sur_module(self): - driver = self.driver - global URL_MATIERE - driver.get(URL_MATIERE) driver.find_element_by_xpath( "//a[contains(@href,'edit_moduleimpl_resp?')]" ).click() @@ -159,6 +120,35 @@ class PythonOrgSearch(unittest.TestCase): driver.get(URL_MATIERE) nomResponsable = driver.find_element_by_id("ens_Responsable") self.assertTrue(SCODOC_CHEF_ID.lower() in nomResponsable.text.lower()) + global isAdmin + isAdmin = False + global isChef + isChef = True + + # Test : Ajout d'un enseignant comme résponsable d'un module + # @expected : Le nom de l'enseignant apparait désormais sur la page d'information du module + def test_031_ajout_enseignant_sur_module(self): + driver = self.driver + global URL_MATIERE + driver.get(URL_MATIERE) + driver.find_element_by_partial_link_text("modifier les enseignants").click() + time.sleep(1) + constructIDEns = ( + SCODOC_ENS_ID.upper() + " " + PRENOM_ENS + " (" + SCODOC_ENS_ID + ")" + ) + driver.find_element_by_id("ens_id").send_keys(constructIDEns) + driver.find_element_by_id("tf_submit").click() + time.sleep(1) + driver.get(URL_MATIERE) + professeurDansModule = driver.find_elements_by_class_name("ens_Dans_Module") + time.sleep(5) + professeurString = [] + for professeur in professeurDansModule: + professeurString.append(professeur.text) + for professeurS in professeurString: + if SCODOC_ENS_ID.lower() in professeurS.lower(): + isThere = True + self.assertTrue(isThere) # Test : Création d'une interrogation en tant que chef des études # @eexpected : L'interrogation apparait désormais dans ce module @@ -188,8 +178,8 @@ class PythonOrgSearch(unittest.TestCase): driver.find_element_by_id("tf_coefficient").send_keys("2") driver.find_element_by_id("tf_submit").click() time.sleep(1) - global isAdmin - isAdmin = False + global isChef + isChef = False global isEns isEns = True self.assertTrue(descriptionInterrogation in driver.page_source) @@ -261,8 +251,8 @@ class PythonOrgSearch(unittest.TestCase): self.assertFalse(False) except NoSuchElementException: self.assertTrue(True) - global isAdmin - isAdmin = True + global isChef + isChef = True global isEns isEns = False @@ -286,10 +276,10 @@ class PythonOrgSearch(unittest.TestCase): driver.find_element_by_class_name("delete_img").click() time.sleep(1) driver.find_element_by_id("tf_submit").click() - global isAdmin - isAdmin = True - global isEns - isEns = False + # global isAdmin + # isAdmin = True + # global isEns + # isEns = False self.assertFalse(descriptionInterrogation in driver.page_source) # Test : Suppression d'un enseignant responsable d'un module @@ -306,8 +296,6 @@ class PythonOrgSearch(unittest.TestCase): time.sleep(1) time.sleep(1) driver.get(URL_MATIERE) - print(SCODOC_ENS_ID) - time.sleep(10) self.assertTrue(SCODOC_ENS_ID not in driver.page_source) # Test : Suppresion du reste des interrogations sans notes diff --git a/06_test_moyenne.py b/06_test_moyenne.py index 333f237..e855e70 100644 --- a/06_test_moyenne.py +++ b/06_test_moyenne.py @@ -1,15 +1,19 @@ import unittest import time +import subprocess import urllib.parse as urlparse -from setup import ( +from setting import ( SCODOC_ADMIN_ID, SCODOC_ADMIN_PASS, BASE_URL, + BASE_NOT_SECURED_URL, + LINK_SCODOC_SERVER, NOM_DPT, SCODOC_ENS_ID, SCODOC_ENS_PASS, SCODOC_CHEF_ID, SCODOC_CHEF_PASS, + NAVIGATEUR, ) from urllib.parse import parse_qs from selenium import webdriver @@ -20,25 +24,82 @@ from selenium.webdriver.support.ui import Select, WebDriverWait from selenium.webdriver.support.select import Select urlMatiere = "" +listeEtudiant = [] class PythonOrgSearch(unittest.TestCase): # Permet de se connecter et se remettre sur la page d'accueil avant chaque test def setUp(self): - #chargement du script creation d'interro - self.driver = webdriver.Firefox() + if NAVIGATEUR == "firefox": + self.driver = webdriver.Firefox() + elif NAVIGATEUR == "chrome": + self.driver = webdriver.Chrome() self.url = BASE_URL + NOM_DPT + "/Scolarite" self.wait = WebDriverWait(self.driver, 10) - self.driver.get(BASE_URL) - self.driver.find_element_by_id("name").send_keys(SCODOC_ENS_ID) - self.driver.find_element_by_id("password").send_keys(SCODOC_ENS_PASS) - self.driver.find_element_by_id("submit").click() + self.driver.get( + "https://" + + SCODOC_ADMIN_ID + + ":" + + SCODOC_ADMIN_PASS + + "@" + + BASE_NOT_SECURED_URL + + "force_admin_authentication" + ) + self.driver.get(self.url) def test_010_ajout_note_multiple(self): - driver = self.driver() + driver = self.driver url = self.url - driver.find_element_by_link_text("DUT Informatique semestre 4").click() - driver.find_element_by_link_text("M4101C").click() - time.sleep(1) - global urlMatiere - urlMatiere = driver.current_url + driver.find_element_by_link_text("semestre 1").click() + matiereAvecEvaluation = driver.find_elements_by_xpath( + "//a[contains(text(),'1 prévues, 0 ok')]" + ) + global listeEtudiant + linkAddNote = "formnotes_note_" + + for evaluation in matiereAvecEvaluation: + URL = driver.current_url + evaluation.click() + self.wait.until(EC.url_changes(URL)) + URL_SEMESTRE = driver.current_url + driver.find_element_by_xpath("//a[contains(@href,'saisie_notes?')]").click() + self.wait.until(EC.url_changes(URL_SEMESTRE)) + for champs in driver.find_elements_by_xpath( + "//input[contains(@id,'" + linkAddNote + "')]" + ): + champs.send_keys(12) + idChamp = champs.get_attribute("id") + idEtud = idChamp[len(linkAddNote) : len(idChamp)] + if idEtud not in listeEtudiant: + listeEtudiant.append(idEtud) + URL = driver.current_url + driver.find_element_by_id("formnotes_submit").click() + self.wait.until(EC.url_changes(URL)) + driver.get(URL_SEMESTRE) + for etudiant in listeEtudiant: + searchBar = driver.find_element_by_id("in-expnom") + searchBar.send_keys(etudiant) + searchBar.submit() + self.assertTrue(driver.find_element_by_id("rcp_moy").text == "12") + + def tearDown(self): + self.driver.close() + + +if __name__ == "__main__": + if NAVIGATEUR == "firefox": + driver = webdriver.Firefox() + else: + driver = webdriver.Chrome() + cmdProcess = ["./scriptCreationDepartement.sh", LINK_SCODOC_SERVER, NOM_DPT] + process = subprocess.Popen(cmdProcess) + process.wait() + cmdProcess = [ + "./scriptExecution.sh", + LINK_SCODOC_SERVER, + NOM_DPT, + "test_scenario3_formation.py", + ] + process = subprocess.Popen(cmdProcess) + process.wait() + unittest.main(warnings="ignore") \ No newline at end of file diff --git a/07_test_admission.py b/07_test_admission.py new file mode 100644 index 0000000..e69de29 diff --git a/UserStoryNew.yaml b/UserStoryNew.yaml index 9ee94f4..87420e6 100644 --- a/UserStoryNew.yaml +++ b/UserStoryNew.yaml @@ -8,7 +8,6 @@ aliases: Role3: &Prof Professeur Role4: &AdminDPT AdminDepartement Page1: &Accueil Accueil - Champs: [&champTest test] Page2: &Absence Absence Page3: &Departement Departement Page4: &Notes Notes @@ -58,7 +57,7 @@ test4: resultat: la page sur laquelle on est dirigée contient un tableau avec la formation crée, dont un id avec titre_nom_formation etat: *DeptCreated page: *Notes - champs: "titre_" + acronyme + champs: "titre_acronyme" role: *AdminDPT createur: Aurélien test5: diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..4e38209 --- /dev/null +++ b/output.txt @@ -0,0 +1,6 @@ +>>> +..... +---------------------------------------------------------------------- +Ran 5 tests in 77.731s + +OK diff --git a/readme.md b/readme.md index 9bd0708..d6097fc 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,6 @@ Environnement de test : Editer le .envmodel pour remplacer les différentes informations qui permettent d'intéragir avec Scodoc (attention au / dans les liens, il y a des exemples) Renommer le fichier en .env -Les tests sont prévus pour fonctionner avec firefox, le webdriver (geckodriver) est intégré dans le projet pour éviter de devoir l'installer manuellement +Les tests sont prévus pour fonctionner avec firefox, le webdriver (geckodriver) est intégré dans le projet pour éviter de devoir l'installer manuellement, il est également possible de préciser un autre webdriver en le précisant dans le .env, en remplaçant firefox par chrome par exemple Les tests sont prévus pour fonctionner en python 3 avec unit test \ No newline at end of file diff --git a/setup.pyc b/setup.pyc deleted file mode 100644 index 4959cdce2135d7c060383e5c9afd9537b36b59cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 583 zcmah{T~ER=6upRi`K|xKgcqn15))$#u+2!+VJP^}m$|G(7RS2KJB&ZZXMdo7z}tm{ z;EQW^+IxC>dwbgQ&*9$JmceN8^D`;Hpd0Q95FN3jG0JF9krxdwc;G(bf(*R8n0SOoFu9}TQVML zS4Rx1v5bZ@mm_EIOS%a6dR(4#}r3%HIvFH z%n7HwSY#7?=%t+UZpWOj)As(W&TlqIigkiPpL@Y{{D?IQ{Lxe3K2M6>xHED`PSAIs zhJG+~@s#GbxaU6Sc(`FbpIe=+bgi>Yp*q@d&b@bMWhZ~ALU%^w