Browse Source

linting applied

rework
Holger Frey 7 years ago
parent
commit
20032eede1
  1. 21
      tests/_functional/layout.py
  2. 42
      tests/_functional/login_logout.py
  3. 39
      tests/_functional/pages.py
  4. 10
      tests/views/pages.py

21
tests/_functional/layout.py

@ -19,20 +19,23 @@ def test_navbar_no_user(testapp): # noqa: F811 @@ -19,20 +19,23 @@ def test_navbar_no_user(testapp): # noqa: F811
assert 'nav-item dropdown' not in result
@pytest.mark.xfail # noqa: F811
@pytest.mark.parametrize(
'username,password,expected', [
('user', 'password', ['/', '/orders', '/logout', '/account']),
('purchaser', 'password', ['/', '/orders', '/logout', '/account']),
('admin', 'password', [
'/', '/orders', '/admin', '/logout', '/account'
]),
@pytest.mark.parametrize( # noqa: F811
'username,password,extras', [
('TerryGilliam', 'Terry', []),
('EricIdle', 'Eric', []),
('TerryJones', 'Terry', ['/admin']),
]
)
def test_navbar_with_user(testapp, username, password, expected):
def test_navbar_with_user(testapp, username, password, extras):
testapp.login(username, password)
result = testapp.get('/faq')
navbar = result.html.find('nav', class_='navbar-dark')
hrefs = [a['href'] for a in navbar.find_all('a')]
expected = ['/', '/orders', '/faq']
expected.extend(extras)
expected.extend(['#', '/logout', '/account'])
print('expected', expected)
print('found ', hrefs)
assert expected == hrefs
assert 'nav-item dropdown' in result
assert username in result

42
tests/_functional/login_logout.py

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
''' functional tests for ordr2.views.pages '''
import pytest
from . import testappsetup, testapp # noqa: F401
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( # noqa: F811
'username,password',
[('John', 'Cleese'), ('unknown user', 'wrong password')]
)
def test_login_denied(testapp, username, password):
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

39
tests/_functional/pages.py

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
''' functional tests for ordr2.views.pages '''
import pytest
from . import testappsetup, testapp # noqa: F401
@ -17,40 +15,3 @@ def test_faq(testapp): # noqa: F811 @@ -17,40 +15,3 @@ 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

10
tests/views/pages.py

@ -32,7 +32,9 @@ def test_login(): @@ -32,7 +32,9 @@ def test_login():
assert result == {'loginerror': False}
@pytest.mark.parametrize('role', [Role.USER, Role.PURCHASER, Role.ADMIN])
@pytest.mark.parametrize( # noqa: F811
'role', [Role.USER, Role.PURCHASER, Role.ADMIN]
)
def test_check_login_ok(dbsession, role):
from ordr.views.pages import check_login
user = get_example_user(role)
@ -44,7 +46,9 @@ def test_check_login_ok(dbsession, role): @@ -44,7 +46,9 @@ def test_check_login_ok(dbsession, role):
assert result.location == 'http://example.com//'
@pytest.mark.parametrize('role', [Role.UNVALIDATED, Role.NEW, Role.INACTIVE])
@pytest.mark.parametrize( # noqa: F811
'role', [Role.UNVALIDATED, Role.NEW, Role.INACTIVE]
)
def test_check_login_not_activated(dbsession, role):
from ordr.views.pages import check_login
user = get_example_user(role)
@ -55,7 +59,7 @@ def test_check_login_not_activated(dbsession, role): @@ -55,7 +59,7 @@ def test_check_login_not_activated(dbsession, role):
assert result == {'loginerror': True}
@pytest.mark.parametrize(
@pytest.mark.parametrize( # noqa: F811
'username,password', [
('', ''),
('TerryGilliam', ''),