Skip to content

Commit

Permalink
tests: some pep8 and real failing if csrf dont match
Browse files Browse the repository at this point in the history
  • Loading branch information
xsteadfastx committed Sep 1, 2016
1 parent 63ee463 commit c65be00
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/test_login.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import re
import requests


URL = 'http://127.0.0.1:80'


def test_login_page():
def test_accessing_login_page():
r = requests.get(URL, allow_redirects=True)

assert r.status_code == 200
Expand All @@ -15,25 +16,30 @@ def test_login_page():
assert 'Username' in r.text


def test_login():
csrf = ''
def test_logging_in():
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)

# get csrf token
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")
# if there is no csrf token the test will fail
pytest.fail('csrf not matched')

data = {
'_username': 'wallabag',
'_password': 'wallabag',
'_csrf_token' : csrf
'_csrf_token': csrf
}

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
Expand Down

0 comments on commit c65be00

Please sign in to comment.