blackify 02

This commit is contained in:
Jean-Marie Place 2021-08-18 15:55:30 +02:00
parent 0d177f7b0b
commit 0d860f2406

View File

@ -1,271 +1,276 @@
# coding: utf8 # coding: utf8
import unittest import unittest
import time import time
import subprocess import subprocess
import HtmlTestRunner import HtmlTestRunner
import createDepartement import createDepartement
import creationSiteDepartement import creationSiteDepartement
import deleteDepartement import deleteDepartement
import creationUtilisateurs import creationUtilisateurs
from setting import ( from setting import (
SCODOC_ADMIN_ID, SCODOC_ADMIN_ID,
SCODOC_ADMIN_PASS, SCODOC_ADMIN_PASS,
SCHEMA, SCHEMA,
SCODOC_SERVER, SCODOC_SERVER,
SCODOC_PORT, SCODOC_PORT,
NOM_DPT, NOM_DPT,
NAVIGATEUR, NAVIGATEUR,
) )
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.select import Select from selenium.webdriver.support.select import Select
URL_ROOT = SCHEMA + "://" + SCODOC_SERVER + ":" + SCODOC_PORT URL_ROOT = SCHEMA + "://" + SCODOC_SERVER + ":" + SCODOC_PORT
URL_AUTH = "/".join((URL_ROOT, "auth", "login")) URL_AUTH = "/".join((URL_ROOT, "auth", "login"))
URL_SCODOC8 = "/".join((URL_ROOT, "index")) URL_SCODOC8 = "/".join((URL_ROOT, "index"))
URL_HOME = "/".join((URL_ROOT, "ScoDoc", "index")) URL_HOME = "/".join((URL_ROOT, "ScoDoc", "index"))
URL_DEPT = "/".join((URL_ROOT, "ScoDoc", NOM_DPT, "Scolarite", "index_html")) URL_DEPT = "/".join((URL_ROOT, "ScoDoc", NOM_DPT, "Scolarite", "index_html"))
URL_ADMIN = "/".join((URL_ROOT, "ScoDoc", "admin")) URL_ADMIN = "/".join((URL_ROOT, "ScoDoc", "admin"))
ACRONYME_FORMATION = "formationtest" ACRONYME_FORMATION = "formationtest"
URL = URL_SCODOC8 URL = URL_SCODOC8
class PythonOrgSearch(unittest.TestCase):
# Permet de se connecter et se remettre sur la page d'accueil avant chaque test class PythonOrgSearch(unittest.TestCase):
def setUp(self): # Permet de se connecter et se remettre sur la page d'accueil avant chaque test
if NAVIGATEUR == "firefox": def setUp(self):
self.driver = webdriver.Firefox() if NAVIGATEUR == "firefox":
else: self.driver = webdriver.Firefox()
self.driver = webdriver.Chrome() else:
self.wait = WebDriverWait(self.driver, 10) self.driver = webdriver.Chrome()
auth_page = URL_AUTH + ("?next=" + URL_HOME).replace("/", "%2F") self.wait = WebDriverWait(self.driver, 10)
self.driver.get(auth_page) auth_page = URL_AUTH
self.driver.find_element_by_id("user_name").send_keys(SCODOC_ADMIN_ID) self.driver.get(auth_page)
self.driver.find_element_by_id("password").send_keys(SCODOC_ADMIN_PASS) self.driver.find_element_by_id("user_name").send_keys(SCODOC_ADMIN_ID)
self.driver.find_element_by_id("submit").click() self.driver.find_element_by_id("password").send_keys(SCODOC_ADMIN_PASS)
self.driver.find_element_by_id("submit").click()
# Test Creer une formation
# @expected : La formation se trouve dans le tableau de la liste des formations # Test Creer une formation
def test_011_create_formation(self): # @expected : La formation se trouve dans le tableau de la liste des formations
global URL def test_011_create_formation(self):
driver = self.driver global URL
wait = self.wait driver = self.driver
driver.get(URL_DEPT) wait = self.wait
driver.find_element_by_id("link-programmes").click() driver.get(URL_DEPT)
URL = driver.current_url driver.find_element_by_id("link-programmes").click()
driver.find_element_by_id("link-create-formation").click() URL = driver.current_url
wait.until(EC.url_changes(URL)) driver.find_element_by_id("link-create-formation").click()
driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_titre").send_keys("TEST") driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION)
driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test") driver.find_element_by_id("tf_titre").send_keys("TEST")
driver.find_element_by_id("tf_submit").click() driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test")
driver.get(URL) driver.find_element_by_id("tf_submit").click()
formations = driver.find_elements_by_class_name("acronyme") driver.get(URL)
textElementAcronyme = [] formations = driver.find_elements_by_class_name("acronyme")
for formation in formations: textElementAcronyme = []
textElementAcronyme.append(formation.text) for formation in formations:
self.assertTrue(ACRONYME_FORMATION in textElementAcronyme) textElementAcronyme.append(formation.text)
self.assertTrue(ACRONYME_FORMATION in textElementAcronyme)
# Test : Changement du nom d'une formation
# @expected : Le nom de la formation est changé sur la page des formations # Test : Changement du nom d'une formation
def test_012_change_name_formation(self): # @expected : Le nom de la formation est changé sur la page des formations
driver = self.driver def test_012_change_name_formation(self):
wait = self.wait driver = self.driver
driver.get(URL) wait = self.wait
id_edit_formation = "edit-formation-" + ACRONYME_FORMATION.replace(" ","-") driver.get(URL)
driver.find_element_by_id(id_edit_formation).click() id_edit_formation = "edit-formation-" + ACRONYME_FORMATION.replace(" ", "-")
wait.until(EC.url_changes(URL)) driver.find_element_by_id(id_edit_formation).click()
driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_submit").click() driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION)
driver.get(URL) driver.find_element_by_id("tf_submit").click()
formations = driver.find_elements_by_class_name("acronyme") driver.get(URL)
text_element_acronyme = [] formations = driver.find_elements_by_class_name("acronyme")
for formation in formations: text_element_acronyme = []
text_element_acronyme.append(formation.text) for formation in formations:
self.assertTrue(ACRONYME_FORMATION + ACRONYME_FORMATION in text_element_acronyme) text_element_acronyme.append(formation.text)
# Remise du nom à celui de départ self.assertTrue(
driver.get(URL) ACRONYME_FORMATION + ACRONYME_FORMATION in text_element_acronyme
id_edit_formation = "edit-formation-" + ACRONYME_FORMATION + ACRONYME_FORMATION )
driver.find_element_by_id(id_edit_formation).click() # Remise du nom à celui de départ
wait.until(EC.url_changes(URL)) driver.get(URL)
driver.find_element_by_id("tf_acronyme").clear() id_edit_formation = "edit-formation-" + ACRONYME_FORMATION + ACRONYME_FORMATION
driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.find_element_by_id(id_edit_formation).click()
driver.find_element_by_id("tf_submit").click() wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_acronyme").clear()
# Test : Création d'une formation avec le même nom qu'une autre déjà existante driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION)
# @expected : La formation n'as pas pu être créée et on arrive donc sur un message d'erreur à la création driver.find_element_by_id("tf_submit").click()
def test_013_same_name_formation(self):
driver = self.driver # Test : Création d'une formation avec le même nom qu'une autre déjà existante
wait = self.wait # @expected : La formation n'as pas pu être créée et on arrive donc sur un message d'erreur à la création
driver.get(URL) def test_013_same_name_formation(self):
driver.find_element_by_id("link-create-formation").click() driver = self.driver
wait.until(EC.url_changes(URL)) wait = self.wait
driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION) driver.get(URL)
driver.find_element_by_id("tf_titre").send_keys("TEST") driver.find_element_by_id("link-create-formation").click()
driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test") wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_submit").click() driver.find_element_by_id("tf_acronyme").send_keys(ACRONYME_FORMATION)
try: driver.find_element_by_id("tf_titre").send_keys("TEST")
driver.find_element_by_class_name("error-message") driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test")
message_erreur_present = True driver.find_element_by_id("tf_submit").click()
except NoSuchElementException: try:
message_erreur_present = False driver.find_element_by_class_name("error-message")
self.assertTrue(message_erreur_present) message_erreur_present = True
except NoSuchElementException:
# Test : Ajout d'une UE dans la formation message_erreur_present = False
# @Expected : L'UE est créée et elle apparait désormais dans la liste d'UE de la formation self.assertTrue(message_erreur_present)
def test_014_ajout_UE(self):
driver = self.driver # Test : Ajout d'une UE dans la formation
wait = self.wait # @Expected : L'UE est créée et elle apparait désormais dans la liste d'UE de la formation
driver.get(URL) def test_014_ajout_UE(self):
id_titre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-") driver = self.driver
driver.find_element_by_id(id_titre).click() wait = self.wait
wait.until(EC.url_changes(URL)) driver.get(URL)
driver.find_element_by_xpath("//a[contains(@href,'ue_create?')]").click() id_titre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_id("tf_titre").send_keys("UE TEST") driver.find_element_by_id(id_titre).click()
driver.find_element_by_id("tf_acronyme").send_keys("TEST") wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_submit").click() driver.find_element_by_xpath("//a[contains(@href,'ue_create?')]").click()
time.sleep(1) driver.find_element_by_id("tf_titre").send_keys("UE TEST")
driver.get(URL) driver.find_element_by_id("tf_acronyme").send_keys("TEST")
driver.find_element_by_id(id_titre).click() driver.find_element_by_id("tf_submit").click()
wait.until(EC.url_changes(URL)) time.sleep(1)
self.assertTrue("TEST UE TEST" in driver.page_source) driver.get(URL)
driver.get(URL) driver.find_element_by_id(id_titre).click()
wait.until(EC.url_changes(URL))
# Test : Ajout d'une matière dans la formation self.assertTrue("TEST UE TEST" in driver.page_source)
# @Expected : La matière est créée et elle apparait désormais sur la page de détail de la formation driver.get(URL)
def test_015_ajout_matiere(self):
driver = self.driver # Test : Ajout d'une matière dans la formation
wait = self.wait # @Expected : La matière est créée et elle apparait désormais sur la page de détail de la formation
driver.get(URL) def test_015_ajout_matiere(self):
nomMat = "unematieretest" driver = self.driver
time.sleep(3) wait = self.wait
idTitre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-") driver.get(URL)
driver.find_element_by_id(idTitre).click() nomMat = "unematieretest"
wait.until(EC.url_changes(URL)) time.sleep(3)
time.sleep(3) idTitre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_xpath("//a[contains(@href,'matiere_create?')]").click() driver.find_element_by_id(idTitre).click()
driver.find_element_by_id("tf_titre").send_keys(nomMat) wait.until(EC.url_changes(URL))
driver.find_element_by_id("tf_numero").send_keys("1") time.sleep(3)
driver.find_element_by_id("tf_submit").click() driver.find_element_by_xpath("//a[contains(@href,'matiere_create?')]").click()
time.sleep(3) driver.find_element_by_id("tf_titre").send_keys(nomMat)
driver.get(URL) driver.find_element_by_id("tf_numero").send_keys("1")
driver.find_element_by_id(idTitre).click() driver.find_element_by_id("tf_submit").click()
time.sleep(3) time.sleep(3)
wait.until(EC.url_changes(URL)) driver.get(URL)
elements = driver.find_elements_by_xpath("//a[contains(@href,'matiere_edit?')]") driver.find_element_by_id(idTitre).click()
matIsPresent = False time.sleep(3)
for element in elements: wait.until(EC.url_changes(URL))
if element.text == nomMat: elements = driver.find_elements_by_xpath("//a[contains(@href,'matiere_edit?')]")
matIsPresent = True matIsPresent = False
self.assertTrue(matIsPresent) for element in elements:
if element.text == nomMat:
# Test : Ajout d'un semestre dans la formation matIsPresent = True
# @Expected : Le semestre est créé et il apparait désormais dans la table des formations self.assertTrue(matIsPresent)
def test_016_ajout_Semestre(self):
driver = self.driver # Test : Ajout d'un semestre dans la formation
wait = self.wait # @Expected : Le semestre est créé et il apparait désormais dans la table des formations
driver.get(URL) def test_016_ajout_Semestre(self):
idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.lower().replace(" ", "-") driver = self.driver
driver.find_element_by_id(idAddSemestre).click() wait = self.wait
wait.until(EC.url_changes(URL)) driver.get(URL)
driver.find_element_by_name("date_debut").send_keys("01/01/2021") idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_name("date_fin").send_keys("30/06/2021") driver.find_element_by_id(idAddSemestre).click()
driver.find_element_by_name("responsable_id").send_keys("BACH Jean-Sebastien (Bach)") wait.until(EC.url_changes(URL))
Select(driver.find_element_by_id("tf_semestre_id")).select_by_value("4") driver.find_element_by_name("date_debut").send_keys("01/01/2021")
driver.find_element_by_id("tf_submit").click() driver.find_element_by_name("date_fin").send_keys("30/06/2021")
wait.until(EC.url_changes(URL)) driver.find_element_by_name("responsable_id").send_keys(
self.assertTrue( "BACH Jean-Sebastien (Bach)"
"Nouveau semestre créé" )
in driver.find_element_by_class_name("head_message").text Select(driver.find_element_by_id("tf_semestre_id")).select_by_value("4")
) driver.find_element_by_id("tf_submit").click()
driver.get(URL) wait.until(EC.url_changes(URL))
self.assertTrue(
self.assertTrue((NOM_DPT.upper() + "-" + "DUT" + "--") in driver.page_source) "Nouveau semestre créé"
in driver.find_element_by_class_name("head_message").text
# Test : Dupplique une formation sous une nouvelle version )
# @expected : La formation est dupliquée et à la version "2" driver.get(URL)
def test_017_creer_nouvelle_version_formation(self):
driver = self.driver self.assertTrue((NOM_DPT.upper() + "-" + "DUT" + "--") in driver.page_source)
wait = self.wait
driver.get(URL) # Test : Dupplique une formation sous une nouvelle version
idTitre = "titre-" + ACRONYME_FORMATION # @expected : La formation est dupliquée et à la version "2"
driver.find_element_by_id(idTitre).click() def test_017_creer_nouvelle_version_formation(self):
wait.until(EC.url_changes(URL)) driver = self.driver
tmpurl = driver.current_url wait = self.wait
driver.find_element_by_xpath( driver.get(URL)
"//a[contains(@href,'formation_create_new_version?')]" idTitre = "titre-" + ACRONYME_FORMATION
).click() driver.find_element_by_id(idTitre).click()
wait.until(EC.url_changes(tmpurl)) wait.until(EC.url_changes(URL))
self.assertTrue("Nouvelle version !" in driver.page_source) tmpurl = driver.current_url
driver.get(URL) driver.find_element_by_xpath(
elements = driver.find_elements_by_class_name("version") "//a[contains(@href,'formation_create_new_version?')]"
version_is_present = False ).click()
for element in elements: wait.until(EC.url_changes(tmpurl))
if element.text == "2": self.assertTrue("Nouvelle version !" in driver.page_source)
version_is_present = True driver.get(URL)
self.assertTrue(version_is_present) elements = driver.find_elements_by_class_name("version")
version_is_present = False
# Test : Supprime une formation après avoir supprimé les semestres qui y sont rattachés for element in elements:
# @expected : La formation n'apparait plus dans le tableau des formations if element.text == "2":
def test_020_delete_formation(self): version_is_present = True
driver = self.driver self.assertTrue(version_is_present)
wait = self.wait
driver.get(URL) # Test : Supprime une formation après avoir supprimé les semestres qui y sont rattachés
id_button_delete = "delete-formation-" + ACRONYME_FORMATION # @expected : La formation n'apparait plus dans le tableau des formations
driver.find_element_by_id(id_button_delete).click() def test_020_delete_formation(self):
wait.until(EC.url_changes(URL)) driver = self.driver
tmp_url_delete = driver.current_url wait = self.wait
liste_semestres = driver.find_elements_by_xpath( driver.get(URL)
"//a[contains(@href, 'formsemestre_status?')]" id_button_delete = "delete-formation-" + ACRONYME_FORMATION
) driver.find_element_by_id(id_button_delete).click()
for semestre in liste_semestres: wait.until(EC.url_changes(URL))
semestre.click() tmp_url_delete = driver.current_url
wait.until(EC.url_changes(URL)) liste_semestres = driver.find_elements_by_xpath(
driver.find_element_by_xpath( "//a[contains(@href, 'formsemestre_status?')]"
"(//a[contains(text(),'Semestre')])[2]" )
).click() for semestre in liste_semestres:
driver.find_element_by_xpath( semestre.click()
"//a[contains(@href, 'formsemestre_delete?')]" wait.until(EC.url_changes(URL))
).click() driver.find_element_by_xpath(
wait.until(EC.url_changes(URL)) "(//a[contains(text(),'Semestre')])[2]"
driver.find_element_by_id("tf_submit").click() ).click()
time.sleep(2) driver.find_element_by_xpath(
driver.find_element_by_xpath("//input[@value='OK']").click() "//a[contains(@href, 'formsemestre_delete?')]"
driver.get(tmp_url_delete) ).click()
driver.find_element_by_xpath( wait.until(EC.url_changes(URL))
"//input[@value='Supprimer cette formation']" driver.find_element_by_id("tf_submit").click()
).click() time.sleep(2)
driver.get(URL) driver.find_element_by_xpath("//input[@value='OK']").click()
formations = driver.find_elements_by_class_name("version") driver.get(tmp_url_delete)
formation_delete = True driver.find_element_by_xpath(
for formation in formations: "//input[@value='Supprimer cette formation']"
if "1" in formation.text: ).click()
formation_delete = False driver.get(URL)
self.assertTrue(formation_delete) formations = driver.find_elements_by_class_name("version")
formation_delete = True
# def test_create_module(self): for formation in formations:
# driver = self.driver if "1" in formation.text:
# element = driver.find_element_by_name("TESTDPT") formation_delete = False
self.assertTrue(formation_delete)
# ferme la fenetre à chaque fin de test
def tearDown(self): # def test_create_module(self):
self.driver.close() # driver = self.driver
# element = driver.find_element_by_name("TESTDPT")
if __name__ == "__main__": # ferme la fenetre à chaque fin de test
deleteDepartement.main() def tearDown(self):
createDepartement.main() self.driver.close()
creationSiteDepartement.main()
creationUtilisateurs.main()
if __name__ == "__main__":
unittest.main( deleteDepartement.main()
testRunner=HtmlTestRunner.HTMLTestRunner( createDepartement.main()
report_name="02_creation_formation_test", creationSiteDepartement.main()
output="./ResultatTest", creationUtilisateurs.main()
combine_reports=True,
) unittest.main(
) testRunner=HtmlTestRunner.HTMLTestRunner(
report_name="02_creation_formation_test",
output="./ResultatTest",
combine_reports=True,
)
)