|
|
|
''' functional tests for ordr2.templates.layout
|
|
|
|
|
|
|
|
The tests for the layout are performed on '/faqs' or '/orders', since these
|
|
|
|
two urls are accessible by either everyone or all active users
|
|
|
|
'''
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from . import testappsetup, testapp # noqa: F401
|
|
|
|
|
|
|
|
|
|
|
|
def test_navbar_no_user(testapp): # noqa: F811
|
|
|
|
''' test the navigation on top of the page for an unauthenticated user '''
|
|
|
|
response = testapp.get('/faq')
|
|
|
|
navbar = response.html.find('nav', class_='navbar-dark')
|
|
|
|
expected = ['/', '/', '/faq', '/register']
|
|
|
|
hrefs = [a['href'] for a in navbar.find_all('a')]
|
|
|
|
|
|
|
|
assert expected == hrefs
|
|
|
|
assert '/orders' not in response
|
|
|
|
assert 'nav-item dropdown' not in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( # noqa: F811
|
|
|
|
'username,password,extras', [
|
|
|
|
('TerryGilliam', 'Terry', []),
|
|
|
|
('EricIdle', 'Eric', []),
|
|
|
|
('TerryJones', 'Terry', ['/admin']),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
def test_navbar_with_user(testapp, username, password, extras):
|
|
|
|
''' test the navigation on top of the page for an authenticated user '''
|
|
|
|
testapp.login(username, password)
|
|
|
|
response = testapp.get('/faq')
|
|
|
|
navbar = response.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'])
|
|
|
|
|
|
|
|
assert expected == hrefs
|
|
|
|
assert 'nav-item dropdown' in response
|
|
|
|
assert username in response
|