From 2a577489599d8ac6f1bae53227b5fcf3cf9ca09e Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 8 Aug 2021 07:39:21 +0200 Subject: [PATCH] fix 02 tests (except Bach problem) --- 01_creation_departement_test.py | 12 +++- 02_creation_formation_test.py | 115 +++++++++++++++++--------------- creationSiteDepartement.py | 25 ++++--- 3 files changed, 82 insertions(+), 70 deletions(-) diff --git a/01_creation_departement_test.py b/01_creation_departement_test.py index 1dea802..818270b 100644 --- a/01_creation_departement_test.py +++ b/01_creation_departement_test.py @@ -22,6 +22,12 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.support.select import Select +URL_ROOT = SCHEMA + "://" + BASE_URL +URL_AUTH = "/".join((URL_ROOT, "auth", "login")) +URL_SCODOC8 = "/".join((URL_ROOT, "index")) +URL_HOME = "/".join((URL_ROOT, "ScoDoc", "index")) +URL_DEPT = "/".join((URL_ROOT, "ScoDoc", NOM_DPT, "Scolarite", "index_html")) +URL_ADMIN = "/".join((URL_ROOT, "ScoDoc", "admin")) class PythonOrgSearch(unittest.TestCase): # Permet de se connecter et se remettre sur la page d'accueil avant chaque test @@ -31,12 +37,12 @@ class PythonOrgSearch(unittest.TestCase): self.driver = webdriver.Firefox() else: self.driver = webdriver.Chrome() - auth_page = SCHEMA + "://" + BASE_SSH_URL + "auth/login?next=%2F" + next_page + auth_page = URL_AUTH + "?next=%2F" + next_page self.driver.get(auth_page) self.driver.find_element_by_id("user_name").send_keys(SCODOC_ADMIN_ID) self.driver.find_element_by_id("password").send_keys(SCODOC_ADMIN_PASS) self.driver.find_element_by_id("submit").click() - self.driver.get(SCHEMA + "://" + BASE_URL) + self.driver.get(URL_SCODOC8) # Test : Verification de la connexion admin effective # @expected : "Bonjour admin" est présent sur la page d'accueil @@ -55,7 +61,7 @@ class PythonOrgSearch(unittest.TestCase): driver.find_element_by_id("create-dept").submit() time.sleep(1) driver.find_element_by_id("tf_submit").click() - driver.get(SCHEMA + "://" + BASE_URL) + driver.get(URL_HOME) self.assertTrue(NOM_DPT in driver.page_source) # Test : Suppresion d'un département, puis lancement d'un script coté serveur pour supprimer sa base de données diff --git a/02_creation_formation_test.py b/02_creation_formation_test.py index adde629..081a457 100644 --- a/02_creation_formation_test.py +++ b/02_creation_formation_test.py @@ -24,10 +24,15 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.support.select import Select -URL = SCHEMA + "://" + BASE_URL + NOM_DPT + "/Scolarite" +URL_ROOT = SCHEMA + "://" + BASE_URL +URL_AUTH = "/".join((URL_ROOT, "auth", "login")) +URL_SCODOC8 = "/".join((URL_ROOT, "index")) +URL_HOME = "/".join((URL_ROOT, "ScoDoc", "index")) +URL_DEPT = "/".join((URL_ROOT, "ScoDoc", NOM_DPT, "Scolarite", "index_html")) +URL_ADMIN = "/".join((URL_ROOT, "ScoDoc", "admin")) ACRONYME_FORMATION = "formationtest" - +URL = URL_SCODOC8 class PythonOrgSearch(unittest.TestCase): # Permet de se connecter et se remettre sur la page d'accueil avant chaque test @@ -37,23 +42,25 @@ class PythonOrgSearch(unittest.TestCase): self.driver = webdriver.Firefox() else: self.driver = webdriver.Chrome() - auth_page = SCHEMA + "://" + BASE_SSH_URL + "auth/login?next=%2F" + next_page + self.wait = WebDriverWait(self.driver, 10) + auth_page = URL_AUTH + ("?next=" + next_page).replace("/", "%2F") self.driver.get(auth_page) self.driver.find_element_by_id("user_name").send_keys(SCODOC_ADMIN_ID) self.driver.find_element_by_id("password").send_keys(SCODOC_ADMIN_PASS) self.driver.find_element_by_id("submit").click() - self.driver.get(SCHEMA + "://" + BASE_URL) + self.driver.get(URL_HOME) # Test Creer une formation # @expected : La formation se trouve dans le tableau de la liste des formations def test_011_create_formation(self): - driver = self.driver global URL - driver.get(URL) + driver = self.driver + wait = self.wait + driver.get(URL_DEPT) driver.find_element_by_id("link-programmes").click() URL = driver.current_url driver.find_element_by_id("link-create-formation").click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.find_element_by_id("tf_titre").send_keys("TEST") driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test") @@ -69,24 +76,24 @@ class PythonOrgSearch(unittest.TestCase): # @expected : Le nom de la formation est changé sur la page des formations def test_012_change_name_formation(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) - idEditFormation = "edit-formation-" + ACRONYME_FORMATION.replace(" ","-") - driver.find_element_by_id(idEditFormation).click() - self.wait.until(EC.url_changes(URL)) + id_edit_formation = "edit-formation-" + ACRONYME_FORMATION.replace(" ","-") + driver.find_element_by_id(id_edit_formation).click() + wait.until(EC.url_changes(URL)) driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.find_element_by_id("tf_submit").click() driver.get(URL) formations = driver.find_elements_by_class_name("acronyme") - textElementAcronyme = [] + text_element_acronyme = [] for formation in formations: - textElementAcronyme.append(formation.text) - self.assertTrue(ACRONYME_FORMATION + ACRONYME_FORMATION in textElementAcronyme) + text_element_acronyme.append(formation.text) + self.assertTrue(ACRONYME_FORMATION + ACRONYME_FORMATION in text_element_acronyme) # Remise du nom à celui de départ driver.get(URL) - idEditFormation = "edit-formation-" + ACRONYME_FORMATION + ACRONYME_FORMATION - driver.find_element_by_id(idEditFormation).click() - self.wait.until(EC.url_changes(URL)) + id_edit_formation = "edit-formation-" + ACRONYME_FORMATION + ACRONYME_FORMATION + driver.find_element_by_id(id_edit_formation).click() + wait.until(EC.url_changes(URL)) driver.find_element_by_id("tf_acronyme").clear() driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.find_element_by_id("tf_submit").click() @@ -95,10 +102,10 @@ class PythonOrgSearch(unittest.TestCase): # @expected : La formation n'as pas pu être créée et on arrive donc sur un message d'erreur à la création def test_013_same_name_formation(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) driver.find_element_by_id("link-create-formation").click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.find_element_by_id("tf_titre").send_keys("TEST") driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test") @@ -114,19 +121,19 @@ class PythonOrgSearch(unittest.TestCase): # @Expected : L'UE est créée et elle apparait désormais dans la liste d'UE de la formation def test_014_ajout_UE(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) - idTitre = "titre-" + ACRONYME_FORMATION.replace(" ", "-") - driver.find_element_by_id(idTitre).click() - self.wait.until(EC.url_changes(URL)) + id_titre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-") + driver.find_element_by_id(id_titre).click() + wait.until(EC.url_changes(URL)) driver.find_element_by_xpath("//a[contains(@href,'ue_create?')]").click() driver.find_element_by_id("tf_titre").send_keys("UE TEST") driver.find_element_by_id("tf_acronyme").send_keys("TEST") driver.find_element_by_id("tf_submit").click() time.sleep(1) driver.get(URL) - driver.find_element_by_id(idTitre).click() - self.wait.until(EC.url_changes(URL)) + driver.find_element_by_id(id_titre).click() + wait.until(EC.url_changes(URL)) self.assertTrue("TEST UE TEST" in driver.page_source) driver.get(URL) @@ -134,13 +141,13 @@ class PythonOrgSearch(unittest.TestCase): # @Expected : La matière est créée et elle apparait désormais sur la page de détail de la formation def test_015_ajout_matiere(self): driver = self.driver - global URL - nomMat = "unematieretest" + wait = self.wait driver.get(URL) + nomMat = "unematieretest" time.sleep(3) - idTitre = "titre-" + ACRONYME_FORMATION + idTitre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-") driver.find_element_by_id(idTitre).click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) time.sleep(3) driver.find_element_by_xpath("//a[contains(@href,'matiere_create?')]").click() driver.find_element_by_id("tf_titre").send_keys(nomMat) @@ -150,7 +157,7 @@ class PythonOrgSearch(unittest.TestCase): driver.get(URL) driver.find_element_by_id(idTitre).click() time.sleep(3) - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) elements = driver.find_elements_by_xpath("//a[contains(@href,'matiere_edit?')]") matIsPresent = False for element in elements: @@ -162,17 +169,17 @@ class PythonOrgSearch(unittest.TestCase): # @Expected : Le semestre est créé et il apparait désormais dans la table des formations def test_016_ajout_Semestre(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) - idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.replace(" ", "-") + idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.lower().replace(" ", "-") driver.find_element_by_id(idAddSemestre).click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) driver.find_element_by_name("date_debut").send_keys("01/01/2021") driver.find_element_by_name("date_fin").send_keys("30/06/2021") - driver.find_element_by_name("responsable_id").send_keys("BACH Test (Bach)") + driver.find_element_by_name("responsable_id").send_keys("HAUSPIE Michael (bach)") Select(driver.find_element_by_id("tf_semestre_id")).select_by_value("4") driver.find_element_by_id("tf_submit").click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) self.assertTrue( "Nouveau semestre créé" in driver.find_element_by_class_name("head_message").text @@ -185,62 +192,62 @@ class PythonOrgSearch(unittest.TestCase): # @expected : La formation est dupliquée et à la version "2" def test_017_creer_nouvelle_version_formation(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) idTitre = "titre-" + ACRONYME_FORMATION driver.find_element_by_id(idTitre).click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) tmpurl = driver.current_url driver.find_element_by_xpath( "//a[contains(@href,'formation_create_new_version?')]" ).click() - self.wait.until(EC.url_changes(tmpurl)) + wait.until(EC.url_changes(tmpurl)) self.assertTrue("Nouvelle version !" in driver.page_source) driver.get(URL) elements = driver.find_elements_by_class_name("version") - versionIsPresent = False + version_is_present = False for element in elements: if element.text == "2": - versionIsPresent = True - self.assertTrue(versionIsPresent) + version_is_present = True + self.assertTrue(version_is_present) # Test : Supprime une formation après avoir supprimé les semestres qui y sont rattachés # @expected : La formation n'apparait plus dans le tableau des formations def test_020_delete_formation(self): driver = self.driver - global URL + wait = self.wait driver.get(URL) - idButtonDelete = "delete-formation-" + ACRONYME_FORMATION - driver.find_element_by_id(idButtonDelete).click() - self.wait.until(EC.url_changes(URL)) - tmpURLDelete = driver.current_url - listeSemestres = driver.find_elements_by_xpath( + id_button_delete = "delete-formation-" + ACRONYME_FORMATION + driver.find_element_by_id(id_button_delete).click() + wait.until(EC.url_changes(URL)) + tmp_url_delete = driver.current_url + liste_semestres = driver.find_elements_by_xpath( "//a[contains(@href, 'formsemestre_status?')]" ) - for semestre in listeSemestres: + for semestre in liste_semestres: semestre.click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) driver.find_element_by_xpath( "(//a[contains(text(),'Semestre')])[2]" ).click() driver.find_element_by_xpath( "//a[contains(@href, 'formsemestre_delete?')]" ).click() - self.wait.until(EC.url_changes(URL)) + wait.until(EC.url_changes(URL)) driver.find_element_by_id("tf_submit").click() time.sleep(2) driver.find_element_by_xpath("//input[@value='OK']").click() - driver.get(tmpURLDelete) + driver.get(tmp_url_delete) driver.find_element_by_xpath( "//input[@value='Supprimer cette formation']" ).click() driver.get(URL) formations = driver.find_elements_by_class_name("version") - formationDelete = True + formation_delete = True for formation in formations: if "1" in formation.text: - formationDelete = False - self.assertTrue(formationDelete) + formation_delete = False + self.assertTrue(formation_delete) # def test_create_module(self): # driver = self.driver diff --git a/creationSiteDepartement.py b/creationSiteDepartement.py index 310829e..0d361b5 100644 --- a/creationSiteDepartement.py +++ b/creationSiteDepartement.py @@ -21,27 +21,26 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.support.select import Select -URL = SCHEMA + "://" + BASE_URL + NOM_DPT + "/Scolarite" +URL_ROOT = SCHEMA + "://" + BASE_URL +URL_AUTH = "/".join((URL_ROOT, "auth", "login")) +URL_SCODOC8 = "/".join((URL_ROOT, "index")) +URL_HOME = "/".join((URL_ROOT, "ScoDoc", "index")) +URL_DEPT = "/".join((URL_ROOT, "ScoDoc", NOM_DPT, "Scolarite", "index_html")) +URL_ADMIN = "/".join((URL_ROOT, "ScoDoc", "admin")) ACRONYME_FORMATION = "FormationTEST" - def main(): + next_page = URL_HOME if NAVIGATEUR == "firefox": driver = webdriver.Firefox() else: driver = webdriver.Chrome() - driver.get( - SCHEMA - + "://" - + SCODOC_ADMIN_ID - + ":" - + SCODOC_ADMIN_PASS - + "@" - + BASE_SSH_URL - + "force_admin_authentication" - ) - driver.get(SCHEMA + "://" + BASE_URL + "scodoc_admin") + auth_page = URL_AUTH + ("?next=" + next_page).replace("/", "%2F") + driver.get(auth_page) + driver.find_element_by_id("user_name").send_keys(SCODOC_ADMIN_ID) + driver.find_element_by_id("password").send_keys(SCODOC_ADMIN_PASS) + driver.find_element_by_id("submit").click() time.sleep(2) try: select = Select(driver.find_element_by_id("create-dept"))