diff --git a/tests/test_login.py b/tests/test_login.py index 1ed70e1..4a1efb1 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -1,3 +1,4 @@ +import re import requests @@ -15,12 +16,26 @@ def test_login_page(): 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('', r.text) + if csrf_match: + csrf = csrf_match.group(1) + else: + print("csrf not matched") - data = { - '_username': 'wallabag', - '_password': 'wallabag' - } + data = { + '_username': 'wallabag', + '_password': 'wallabag', + '_csrf_token' : csrf + } - r = s.post(URL + '/login_check', data=data) - print(r.text) + r = client.post(URL + '/login_check', cookies=jar, data=data) + 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