added login tests (headless and with selenium)

blueprint_refactoring
Simon Pirkelmann 2022-01-25 00:09:14 +01:00
parent e0a22f770d
commit bb022fd1ce
1 changed files with 39 additions and 0 deletions

View 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)