1
0
mirror of https://github.com/wallabag/docker synced 2025-12-21 21:51:53 +00:00

Merge pull request #1 from Strubbl/test_login

test_login: add login with csrf token and check if it was successful
This commit is contained in:
xsteadfastx
2016-09-01 09:15:18 +02:00
committed by GitHub

View File

@@ -1,3 +1,4 @@
import re
import requests import requests
@@ -15,12 +16,26 @@ def test_login_page():
def test_login(): def test_login():
with requests.Session() as s: csrf = ''
client = requests.session()
r = client.get(URL, allow_redirects=True)
jar = r.cookies
csrf_match = re.search('<input type="hidden" name="_csrf_token" value="(.*)" />', r.text)
if csrf_match:
csrf = csrf_match.group(1)
else:
print("csrf not matched")
data = { data = {
'_username': 'wallabag', '_username': 'wallabag',
'_password': 'wallabag' '_password': 'wallabag',
'_csrf_token' : csrf
} }
r = s.post(URL + '/login_check', data=data) r = client.post(URL + '/login_check', cookies=jar, data=data)
print(r.text) print(r.text)
assert r.status_code == 200
assert '/unread/list' in r.text
assert '/starred/list' in r.text
assert '/archive/list' in r.text
assert '/all/list' in r.text