''' functional tests for ordr2.views.pages ''' import pytest from . import testappsetup, testapp # noqa: F401 def test_login_get(testapp): # noqa: F811 ''' test the login form ''' response = testapp.get('/account/login') active = response.html.find('li', class_='active') form = response.form assert active.a['href'] == 'http://localhost/' assert form.action == 'http://localhost/account/login' def test_login_ok(testapp): # noqa: F811 ''' test login form with valid credentials ''' response = testapp.get('/account/login') login_form = response.forms[0] login_form['username'] = 'TerryGilliam' login_form['password'] = 'Terry' response = login_form.submit() assert response.location == 'http://localhost/' response = testapp.get('/faq') assert 'TerryGilliam' in response @pytest.mark.parametrize( # noqa: F811 'username,password', [('John', 'Cleese'), ('unknown user', 'wrong password')] ) def test_login_denied(testapp, username, password): ''' test login form with invalid credentials ''' response = testapp.get('/account/login') login_form = response.forms[0] login_form['username'] = 'John' login_form['password'] = 'Cleese' response = login_form.submit() assert 'account is not activated' in response def test_logout(testapp): # noqa: F811 ''' test login form with valid credentials ''' response = testapp.get('/account/login') login_form = response.forms[0] login_form['username'] = 'TerryGilliam' login_form['password'] = 'Terry' login_form.submit() response = testapp.get('/faq') assert 'TerryGilliam' in response response = testapp.get('/account/logout') assert response.location == 'http://localhost/' response = testapp.get('/faq') assert 'TerryGilliam' not in response