Tests
This commit is contained in:
69
tests_examples/test_app.py
Normal file
69
tests_examples/test_app.py
Normal file
@ -0,0 +1,69 @@
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
import routing
|
||||
import init
|
||||
from tests_examples import login_data
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
app = init.create(testing=True)
|
||||
app.config.update({
|
||||
"TESTING": True,
|
||||
})
|
||||
|
||||
routing.init_routes(app)
|
||||
|
||||
# other setup can go here
|
||||
|
||||
yield app
|
||||
|
||||
# clean up / reset resources here
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def runner(app):
|
||||
return app.test_cli_runner()
|
||||
|
||||
|
||||
def login(client):
|
||||
client.post('/log-in', data=dict(email=login_data.email, password=login_data.password),
|
||||
follow_redirects=True)
|
||||
cookie = client.get_cookie("cnsc")
|
||||
return len(cookie.value) == 32
|
||||
|
||||
|
||||
def test_login(client):
|
||||
loginpage = client.get("/log-in", follow_redirects=True)
|
||||
assert b"Einloggen" in loginpage.data
|
||||
assert loginpage.status_code == 200
|
||||
loginpage_html = BeautifulSoup(loginpage.text, "lxml")
|
||||
login_form = loginpage_html.find("form")
|
||||
login_action = login_form.get("action")
|
||||
login_request = client.post(login_action, data=dict(email=login_data.email, password=login_data.password),
|
||||
follow_redirects=True)
|
||||
assert login_request.status_code == 200
|
||||
assert b"Willkommen, " in login_request.data
|
||||
|
||||
|
||||
def test_noten(client):
|
||||
if login(client):
|
||||
notenpage = client.get("/theorie/noten", follow_redirects=True)
|
||||
assert notenpage.status_code == 200
|
||||
|
||||
assert b"Deine Noten im" in notenpage.data
|
||||
|
||||
|
||||
def test_logout(client):
|
||||
if login(client):
|
||||
loginpage = client.get("/log-out", follow_redirects=True)
|
||||
assert loginpage.status_code == 200
|
||||
assert b"Einloggen" in loginpage.data
|
||||
cookie = client.get_cookie("cnsc")
|
||||
assert len(cookie.value) != 32 # CNSC-Länge: 32 → CNSC darf ausgeloggt nicht gesetzt sein
|
||||
Reference in New Issue
Block a user