added login tests (headless and with selenium)
This commit is contained in:
parent
e0a22f770d
commit
bb022fd1ce
39
tests/test_webinterface.py
Normal file
39
tests/test_webinterface.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
def test_login(browser, live_server):
|
||||||
|
response = browser.get(f'http://localhost:{live_server.port}')
|
||||||
|
|
||||||
|
assert '<h1>Space Zugangsverwaltung</h1>' in browser.page_source
|
||||||
|
|
||||||
|
response = browser.get(f'http://localhost:{live_server.port}/login')
|
||||||
|
|
||||||
|
email_form = browser.find_element_by_id('email').send_keys('gandalf@shire.me')
|
||||||
|
password_form = browser.find_element_by_id('password').send_keys('shadowfax')
|
||||||
|
submit_button = browser.find_element_by_id('submit').click()
|
||||||
|
|
||||||
|
assert 'Tür öffnen' in browser.page_source
|
||||||
|
|
||||||
|
|
||||||
|
def login(client, payload):
|
||||||
|
return client.post('/login', data=payload, follow_redirects=True)
|
||||||
|
|
||||||
|
def test_login_headless(client):
|
||||||
|
# extract csrf token from the login page source
|
||||||
|
response = client.get('/login')
|
||||||
|
soup = BeautifulSoup(response.data)
|
||||||
|
csrf_token = soup.find('input', attrs={'id': 'csrf_token'})['value']
|
||||||
|
|
||||||
|
# send login information
|
||||||
|
payload = {
|
||||||
|
'csrf_token': csrf_token,
|
||||||
|
'email': 'gandalf@shire.me',
|
||||||
|
'password': 'shadowfax'
|
||||||
|
}
|
||||||
|
response = login(client, payload)
|
||||||
|
soup = BeautifulSoup(response.data)
|
||||||
|
|
||||||
|
# make sure login succeeded -> Tür öffnen button will appear
|
||||||
|
assert any(['Tür öffnen' in link.contents[0] for link in soup.findAll('a', attrs={'class': ['btn'], 'role': 'button'})])
|
||||||
|
|
||||||
|
def logout(client):
|
||||||
|
return client.get('/logout', follow_redirects=True)
|
Loading…
Reference in New Issue
Block a user