Refactoring
This commit is contained in:
@ -8,25 +8,34 @@ from tests_examples import login_data
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
"""
|
||||
Erstellt die App und konfiguriert sie zum Test-Modus
|
||||
:yield app:
|
||||
"""
|
||||
app = init.create(testing=True)
|
||||
app.config.update({
|
||||
"TESTING": True,
|
||||
})
|
||||
routing.init_routes(app)
|
||||
routing.initRoutes(app)
|
||||
yield app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
"""
|
||||
Liefert einen Test-Client
|
||||
:param app:
|
||||
:return client:
|
||||
"""
|
||||
return app.test_client(use_cookies=True)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def runner(app):
|
||||
return app.test_cli_runner()
|
||||
|
||||
|
||||
def login(client):
|
||||
"""
|
||||
Hilfsfunktion, die den Client einloggt
|
||||
:param client:
|
||||
:return Bool (true if successful, false otherwise):
|
||||
"""
|
||||
client.post('/log-in', data=dict(email=login_data.email, password=login_data.password),
|
||||
follow_redirects=True)
|
||||
cookie = client.get_cookie("cnsc")
|
||||
@ -37,6 +46,10 @@ def login(client):
|
||||
|
||||
|
||||
def test_login(client):
|
||||
"""
|
||||
Testet die Login-Funktion
|
||||
:param client:
|
||||
"""
|
||||
loginpage = client.get("/log-in", follow_redirects=True)
|
||||
assert b"Einloggen" in loginpage.data
|
||||
assert loginpage.status_code == 200
|
||||
@ -51,6 +64,10 @@ def test_login(client):
|
||||
|
||||
|
||||
def test_kurssetup(client):
|
||||
"""
|
||||
Testet die Konfiguration eines Kurses
|
||||
:param client:
|
||||
"""
|
||||
if login(client):
|
||||
kurspage = client.get("/set-up", follow_redirects=True)
|
||||
assert kurspage.status_code == 200
|
||||
@ -70,14 +87,18 @@ def test_kurssetup(client):
|
||||
|
||||
|
||||
def test_semestersetup(client):
|
||||
"""
|
||||
Testet die Konfiguration eines Semesters
|
||||
:param client:
|
||||
"""
|
||||
if login(client):
|
||||
semesterpage = client.get("/set-up/semester", follow_redirects=True)
|
||||
assert semesterpage.status_code == 200
|
||||
semesterpage_html = BeautifulSoup(semesterpage.text, "lxml")
|
||||
semesterform = semesterpage_html.find("form")
|
||||
semesterform_action = semesterform.get("action")
|
||||
semesterform_options = semesterform.find_all("option")
|
||||
nextpage = client.post(semesterform_action, data=dict(sem=semesterform_options[-1].get("value")),
|
||||
semesterpageHTML = BeautifulSoup(semesterpage.text, "lxml")
|
||||
semesterform = semesterpageHTML.find("form")
|
||||
semesterformAction = semesterform.get("action")
|
||||
semesterformOptions = semesterform.find_all("option")
|
||||
nextpage = client.post(semesterformAction, data=dict(sem=semesterformOptions[-1].get("value")),
|
||||
follow_redirects=True)
|
||||
assert nextpage.status_code == 200
|
||||
assert b"Willkommen, " in nextpage.data
|
||||
@ -86,30 +107,38 @@ def test_semestersetup(client):
|
||||
|
||||
|
||||
def test_noten(client):
|
||||
"""
|
||||
Testet das Abrufen der Noten aus zwei verschiedenen Semestern
|
||||
:param client:
|
||||
"""
|
||||
if login(client):
|
||||
notenpage = client.get("/theorie/noten", follow_redirects=True)
|
||||
assert notenpage.status_code == 200
|
||||
notenpage_html = BeautifulSoup(notenpage.text, "lxml")
|
||||
notenpage_heading = notenpage_html.find("h1")
|
||||
notenpage_form = notenpage_html.find("form")
|
||||
notenpage_action = notenpage_form.get("action")
|
||||
notenpage_selection = notenpage_form.find("select")
|
||||
notenpage_options = notenpage_selection.find_all("option")
|
||||
notenpage_semester = "Not found!"
|
||||
notenpageHTML = BeautifulSoup(notenpage.text, "lxml")
|
||||
notenpageHeading = notenpageHTML.find("h1")
|
||||
notenpageForm = notenpageHTML.find("form")
|
||||
notenpageAction = notenpageForm.get("action")
|
||||
notenpageSelection = notenpageForm.find("select")
|
||||
notenpageOptions = notenpageSelection.find_all("option")
|
||||
notenpageSemester = "Not found!"
|
||||
nextpage = "Not found!"
|
||||
for i in notenpage_options:
|
||||
for i in notenpageOptions:
|
||||
if i.get("selected") == "":
|
||||
notenpage_semester = i.text[:-1]
|
||||
notenpageSemester = i.text[:-1]
|
||||
else:
|
||||
nextpage = i.get("value")
|
||||
assert notenpage_semester.encode("utf-8") in notenpage_heading.encode("utf-8")
|
||||
nextpage = client.post(notenpage_action, data=dict(sem=nextpage), follow_redirects=True)
|
||||
assert notenpageSemester.encode("utf-8") in notenpageHeading.encode("utf-8")
|
||||
nextpage = client.post(notenpageAction, data=dict(sem=nextpage), follow_redirects=True)
|
||||
assert nextpage.status_code == 200
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
def test_logout(client):
|
||||
"""
|
||||
Testet die Logout-Funktion
|
||||
:param client:
|
||||
"""
|
||||
if login(client):
|
||||
loginpage = client.get("/log-out", follow_redirects=True)
|
||||
assert loginpage.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user