from bs4 import BeautifulSoup def test_login(browser, live_server): response = browser.get(f'http://localhost:{live_server.port}') assert '

Space Zugangsverwaltung

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