ScodocTestClient/06_test_moyenne.py

223 lines
8.3 KiB
Python

import unittest
import time
import subprocess
import urllib.parse as urlparse
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
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support.select import Select
urlMatiere = ""
listeEtudiant = []
global MOY_UE1
global MOY_UE2
global URL_SEMESTRE
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()
elif NAVIGATEUR == "chrome":
self.driver = webdriver.Chrome()
self.url = BASE_URL + NOM_DPT + "/Scolarite"
self.wait = WebDriverWait(self.driver, 10)
self.driver.get(
"https://"
+ SCODOC_ADMIN_ID
+ ":"
+ SCODOC_ADMIN_PASS
+ "@"
+ BASE_NOT_SECURED_URL
+ "force_admin_authentication"
)
# Test: Ajout de note pour deux élèves dans une seule UE et vérifie si la moyenne de cet UE sur la fiche étudiante correspondant à la valeur rentrée
# @expected : La note rentrée et la moyenne sont identiques
def test_010_ajout_note_multiple_pour_une_ue(self):
global listeEtudiant
global MOY_UE1
global URL_SEMESTRE
driver = self.driver
url = self.url
driver.get(url)
linkAddNote = "formnotes_note_"
driver.find_element_by_link_text("semestre 1").click()
self.wait.until(EC.url_changes(url))
URL_SEMESTRE = driver.current_url
ue_name = driver.find_elements_by_class_name("status_ue_acro")[0].text
driver.find_element_by_link_text("M1101").click()
self.wait.until(EC.url_changes(URL_SEMESTRE))
driver.find_element_by_xpath("//a[contains(@href,'saisie_notes?')]").click()
self.wait.until(EC.url_changes(URL_SEMESTRE))
URL = driver.current_url
for champs in driver.find_elements_by_xpath(
"//input[contains(@id,'" + linkAddNote + "')]"
):
champs.clear()
champs.send_keys(12)
idChamp = champs.get_attribute("id")
idEtud = idChamp[len(linkAddNote) : len(idChamp)]
if idEtud not in listeEtudiant:
listeEtudiant.append(idEtud)
driver.find_element_by_id("formnotes_submit").click()
self.wait.until(EC.url_changes(URL))
driver.get(URL_SEMESTRE)
noteBonne = True
print(listeEtudiant)
for etudiant in listeEtudiant:
searchBar = driver.find_element_by_id("in-expnom")
searchBar.send_keys(etudiant)
searchBar.submit()
time.sleep(5)
MOY_UE1 = driver.find_element_by_id("ue_" + ue_name).text
if "12" not in MOY_UE1:
noteBonne = False
self.assertTrue(noteBonne)
# matiereAvecEvaluation = driver.find_elements_by_xpath("//a[contains(text(),'1 prévues, 0 ok')]")
#
# 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)
# self.wait.until(EC.url_changes(URL))
# matiereAvecEvaluation = driver.find_elements_by_xpath(
# "//a[contains(text(),'1 prévues, 0 ok')]"
# )
def test_020_ajout_note_seconde_ue(self):
global listeEtudiant
global MOY_UE2
global URL_SEMESTRE
linkAddNote = "formnotes_note_"
driver = self.driver
url = self.url
driver.get(URL_SEMESTRE)
ue_name = driver.find_elements_by_class_name("status_ue_acro")[1].text
driver.find_element_by_link_text("M1201").click()
self.wait.until(EC.url_changes(URL_SEMESTRE))
driver.find_element_by_xpath("//a[contains(@href,'saisie_notes?')]").click()
self.wait.until(EC.url_changes(URL_SEMESTRE))
URL = driver.current_url
for champs in driver.find_elements_by_xpath(
"//input[contains(@id,'" + linkAddNote + "')]"
):
champs.clear()
champs.send_keys(8)
driver.find_element_by_id("formnotes_submit").click()
self.wait.until(EC.url_changes(URL))
driver.get(URL_SEMESTRE)
noteBonne = True
for etudiant in listeEtudiant:
URL = driver.current_url
searchBar = driver.find_element_by_id("in-expnom")
searchBar.send_keys(etudiant)
searchBar.submit()
time.sleep(5)
MOY_UE2 = driver.find_element_by_id("ue_" + ue_name).text
if "8" not in MOY_UE2:
noteBonne = False
self.assertTrue(noteBonne)
def test_030_verification_moyenne_generale(self):
global listeEtudiant
global MOY_UE1
global MOY_UE2
coeffUE1 = 2
coeffUE2 = 2
driver = self.driver
url = self.url
driver.get(url)
moyenneBonne = True
for etudiant in listeEtudiant:
searchBar = driver.find_element_by_id("in-expnom")
searchBar.send_keys(etudiant)
searchBar.submit()
self.wait.until(EC.url_changes(url))
if (
(float(MOY_UE1) * coeffUE1 + float(MOY_UE2) * coeffUE2)
/ (coeffUE1 + coeffUE2)
) != float(driver.find_element_by_class_name("rcp_moy").text):
moyenneBonne = False
self.assertTrue(moyenneBonne)
def test_040_modification_coefficiant_module(self):
global listeEtudiant
moyUE1 = 3
coeffUE1 = 3
coeffUE2 = 2
driver = self.driver
url = self.url
driver.get(url)
URL = driver.current_url
driver.find_element_by_id("ProgrammesLink").click()
driver.find_element_by_id("titre_DUT Info").click()
driver.find_element_by_xpath("//span[contains(text(),'M1101')]").click()
driver.find_element_by_id("tf_coefficient").clear()
driver.find_element_by_id("tf_coefficient").send_keys(moyUE1)
driver.find_element_by_id("tf_submit").click()
self.wait.until(EC.url_changes(URL))
moyenneBonne = True
for etudiant in listeEtudiant:
URL = driver.current_url
searchBar = driver.find_element_by_id("in-expnom")
searchBar.send_keys(etudiant)
searchBar.submit()
self.wait.until(EC.url_changes(URL))
if (
(float(MOY_UE1) * coeffUE1 + float(MOY_UE2) * coeffUE2)
/ (coeffUE1 + coeffUE2)
) != float(driver.find_element_by_class_name("rcp_moy").text):
moyenneBonne = False
self.assertTrue(moyenneBonne)
def tearDown(self):
self.driver.close()
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_scenario3_formation.py",
]
process = subprocess.Popen(cmdProcess)
process.wait()
unittest.main(warnings="ignore")