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
import unittest
import time
import subprocess
import HtmlTestRunner
import createDepartement
import creationSiteDepartement
import deleteDepartement
import creationUtilisateurs
from setting import (
SCODOC_ADMIN_ID,
SCODOC_ADMIN_PASS,
SCHEMA,
SCODOC_SERVER,
SCODOC_PORT,
NOM_DPT,
NAVIGATEUR,
)
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.select import Select
URL_ROOT = SCHEMA + "://" + SCODOC_SERVER + ":" + SCODOC_PORT
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
def setUp(self):
if NAVIGATEUR == "firefox":
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Chrome()
self.wait = WebDriverWait(self.driver, 10)
auth_page = URL_AUTH + ("?next=" + URL_HOME).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()
# Test Creer une formation
# @expected : La formation se trouve dans le tableau de la liste des formations
def test_011_create_formation(self):
global 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()
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")
driver.find_element_by_id("tf_submit").click()
driver.get(URL)
formations = driver.find_elements_by_class_name("acronyme")
textElementAcronyme = []
for formation in formations:
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
def test_012_change_name_formation(self):
driver = self.driver
wait = self.wait
driver.get(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")
text_element_acronyme = []
for formation in formations:
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)
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()
# Test : Création d'une formation avec le même nom qu'une autre déjà existante
# @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
wait = self.wait
driver.get(URL)
driver.find_element_by_id("link-create-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_titre").send_keys("TEST")
driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test")
driver.find_element_by_id("tf_submit").click()
try:
driver.find_element_by_class_name("error-message")
message_erreur_present = True
except NoSuchElementException:
message_erreur_present = False
self.assertTrue(message_erreur_present)
# Test : Ajout d'une UE dans la formation
# @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
wait = self.wait
driver.get(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(id_titre).click()
wait.until(EC.url_changes(URL))
self.assertTrue("TEST UE TEST" in driver.page_source)
driver.get(URL)
# Test : Ajout d'une matière dans la formation
# @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
wait = self.wait
driver.get(URL)
nomMat = "unematieretest"
time.sleep(3)
idTitre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_id(idTitre).click()
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)
driver.find_element_by_id("tf_numero").send_keys("1")
driver.find_element_by_id("tf_submit").click()
time.sleep(3)
driver.get(URL)
driver.find_element_by_id(idTitre).click()
time.sleep(3)
wait.until(EC.url_changes(URL))
elements = driver.find_elements_by_xpath("//a[contains(@href,'matiere_edit?')]")
matIsPresent = False
for element in elements:
if element.text == nomMat:
matIsPresent = True
self.assertTrue(matIsPresent)
# Test : Ajout d'un semestre dans la formation
# @Expected : Le semestre est créé et il apparait désormais dans la table des formations
def test_016_ajout_Semestre(self):
driver = self.driver
wait = self.wait
driver.get(URL)
idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_id(idAddSemestre).click()
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 Jean-Sebastien (Bach)")
Select(driver.find_element_by_id("tf_semestre_id")).select_by_value("4")
driver.find_element_by_id("tf_submit").click()
wait.until(EC.url_changes(URL))
self.assertTrue(
"Nouveau semestre créé"
in driver.find_element_by_class_name("head_message").text
)
driver.get(URL)
self.assertTrue((NOM_DPT.upper() + "-" + "DUT" + "--") in driver.page_source)
# Test : Dupplique une formation sous une nouvelle version
# @expected : La formation est dupliquée et à la version "2"
def test_017_creer_nouvelle_version_formation(self):
driver = self.driver
wait = self.wait
driver.get(URL)
idTitre = "titre-" + ACRONYME_FORMATION
driver.find_element_by_id(idTitre).click()
wait.until(EC.url_changes(URL))
tmpurl = driver.current_url
driver.find_element_by_xpath(
"//a[contains(@href,'formation_create_new_version?')]"
).click()
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")
version_is_present = False
for element in elements:
if element.text == "2":
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
wait = self.wait
driver.get(URL)
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 liste_semestres:
semestre.click()
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()
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(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")
formation_delete = True
for formation in formations:
if "1" in formation.text:
formation_delete = False
self.assertTrue(formation_delete)
# def test_create_module(self):
# driver = self.driver
# element = driver.find_element_by_name("TESTDPT")
# ferme la fenetre à chaque fin de test
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
deleteDepartement.main()
createDepartement.main()
creationSiteDepartement.main()
creationUtilisateurs.main()
unittest.main(
testRunner=HtmlTestRunner.HTMLTestRunner(
report_name="02_creation_formation_test",
output="./ResultatTest",
combine_reports=True,
)
)
# coding: utf8
import unittest
import time
import subprocess
import HtmlTestRunner
import createDepartement
import creationSiteDepartement
import deleteDepartement
import creationUtilisateurs
from setting import (
SCODOC_ADMIN_ID,
SCODOC_ADMIN_PASS,
SCHEMA,
SCODOC_SERVER,
SCODOC_PORT,
NOM_DPT,
NAVIGATEUR,
)
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.select import Select
URL_ROOT = SCHEMA + "://" + SCODOC_SERVER + ":" + SCODOC_PORT
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
def setUp(self):
if NAVIGATEUR == "firefox":
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Chrome()
self.wait = WebDriverWait(self.driver, 10)
auth_page = URL_AUTH
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()
# Test Creer une formation
# @expected : La formation se trouve dans le tableau de la liste des formations
def test_011_create_formation(self):
global 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()
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")
driver.find_element_by_id("tf_submit").click()
driver.get(URL)
formations = driver.find_elements_by_class_name("acronyme")
textElementAcronyme = []
for formation in formations:
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
def test_012_change_name_formation(self):
driver = self.driver
wait = self.wait
driver.get(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")
text_element_acronyme = []
for formation in formations:
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)
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()
# Test : Création d'une formation avec le même nom qu'une autre déjà existante
# @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
wait = self.wait
driver.get(URL)
driver.find_element_by_id("link-create-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_titre").send_keys("TEST")
driver.find_element_by_id("tf_titre_officiel").send_keys("formation de test")
driver.find_element_by_id("tf_submit").click()
try:
driver.find_element_by_class_name("error-message")
message_erreur_present = True
except NoSuchElementException:
message_erreur_present = False
self.assertTrue(message_erreur_present)
# Test : Ajout d'une UE dans la formation
# @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
wait = self.wait
driver.get(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(id_titre).click()
wait.until(EC.url_changes(URL))
self.assertTrue("TEST UE TEST" in driver.page_source)
driver.get(URL)
# Test : Ajout d'une matière dans la formation
# @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
wait = self.wait
driver.get(URL)
nomMat = "unematieretest"
time.sleep(3)
idTitre = "titre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_id(idTitre).click()
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)
driver.find_element_by_id("tf_numero").send_keys("1")
driver.find_element_by_id("tf_submit").click()
time.sleep(3)
driver.get(URL)
driver.find_element_by_id(idTitre).click()
time.sleep(3)
wait.until(EC.url_changes(URL))
elements = driver.find_elements_by_xpath("//a[contains(@href,'matiere_edit?')]")
matIsPresent = False
for element in elements:
if element.text == nomMat:
matIsPresent = True
self.assertTrue(matIsPresent)
# Test : Ajout d'un semestre dans la formation
# @Expected : Le semestre est créé et il apparait désormais dans la table des formations
def test_016_ajout_Semestre(self):
driver = self.driver
wait = self.wait
driver.get(URL)
idAddSemestre = "add-semestre-" + ACRONYME_FORMATION.lower().replace(" ", "-")
driver.find_element_by_id(idAddSemestre).click()
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 Jean-Sebastien (Bach)"
)
Select(driver.find_element_by_id("tf_semestre_id")).select_by_value("4")
driver.find_element_by_id("tf_submit").click()
wait.until(EC.url_changes(URL))
self.assertTrue(
"Nouveau semestre créé"
in driver.find_element_by_class_name("head_message").text
)
driver.get(URL)
self.assertTrue((NOM_DPT.upper() + "-" + "DUT" + "--") in driver.page_source)
# Test : Dupplique une formation sous une nouvelle version
# @expected : La formation est dupliquée et à la version "2"
def test_017_creer_nouvelle_version_formation(self):
driver = self.driver
wait = self.wait
driver.get(URL)
idTitre = "titre-" + ACRONYME_FORMATION
driver.find_element_by_id(idTitre).click()
wait.until(EC.url_changes(URL))
tmpurl = driver.current_url
driver.find_element_by_xpath(
"//a[contains(@href,'formation_create_new_version?')]"
).click()
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")
version_is_present = False
for element in elements:
if element.text == "2":
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
wait = self.wait
driver.get(URL)
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 liste_semestres:
semestre.click()
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()
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(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")
formation_delete = True
for formation in formations:
if "1" in formation.text:
formation_delete = False
self.assertTrue(formation_delete)
# def test_create_module(self):
# driver = self.driver
# element = driver.find_element_by_name("TESTDPT")
# ferme la fenetre à chaque fin de test
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
deleteDepartement.main()
createDepartement.main()
creationSiteDepartement.main()
creationUtilisateurs.main()
unittest.main(
testRunner=HtmlTestRunner.HTMLTestRunner(
report_name="02_creation_formation_test",
output="./ResultatTest",
combine_reports=True,
)
)