You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
''' functional tests for ordr2.views.pages ''' |
|
|
|
import pytest |
|
|
|
from . import testappsetup, testapp # noqa: F401 |
|
|
|
|
|
def test_welcome(testapp): # noqa: F811 |
|
result = testapp.get('/') |
|
assert result.location == 'http://localhost/login' |
|
testapp.login('TerryGilliam', 'Terry') |
|
result = testapp.get('/') |
|
assert result.location == 'http://localhost/orders' |
|
|
|
|
|
def test_faq(testapp): # noqa: F811 |
|
result = testapp.get('/faq') |
|
active = result.html.find('li', class_='active') |
|
assert active.a['href'] == '/faq' |
|
|
|
|
|
def test_login_get(testapp): # noqa: F811 |
|
result = testapp.get('/login') |
|
active = result.html.find('li', class_='active') |
|
assert active.a['href'] == '/' |
|
expected = {'/', '/faq', '/register', '/forgot', '/register'} |
|
hrefs = {a['href'] for a in result.html.find_all('a')} |
|
assert expected == hrefs |
|
forms = result.html.find_all('form') |
|
assert len(forms) == 1 |
|
login_form = forms[0] |
|
assert login_form['action'] == '/login' |
|
assert login_form['method'] == 'POST' |
|
assert 'account is not activated' not in result |
|
|
|
|
|
def test_login_ok(testapp): # noqa: F811 |
|
result = testapp.get('/login') |
|
login_form = result.forms[0] |
|
login_form['username'] = 'TerryGilliam' |
|
login_form['password'] = 'Terry' |
|
result = login_form.submit() |
|
assert result.location == 'http://localhost/' |
|
|
|
|
|
@pytest.mark.parametrize( |
|
'username,password', |
|
[('John', 'Cleese'), ('unknown user', 'wrong password')] |
|
) |
|
def test_login_denied(testapp, username, password): # noqa: F811 |
|
result = testapp.get('/login') |
|
login_form = result.forms[0] |
|
login_form['username'] = 'John' |
|
login_form['password'] = 'Cleese' |
|
result = login_form.submit() |
|
assert 'account is not activated' in result
|
|
|