''' 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 = [ 'http://localhost/', 'http://localhost/', 'http://localhost/faq', 'http://localhost/account/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', ['http://localhost/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 = [ 'http://localhost/', 'http://localhost/orders', 'http://localhost/faq' ] expected.extend(extras) expected.extend([ '#', 'http://localhost/account/logout', 'http://localhost/account/settings', 'http://localhost/account/password' ]) assert expected == hrefs assert 'nav-item dropdown' in response assert username in response