From 53f36e85664571eba2065d7503241c5ddf2003a8 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Mon, 16 Apr 2018 17:07:37 +0200 Subject: [PATCH] added main navigation to layout template --- ordr/resources/__init__.py | 2 + ordr/templates/layout.jinja2 | 62 +++++++++++++++++++++++++---- ordr/templates/pages/welcome.jinja2 | 33 +++++++++++++-- tests/_functional/__init__.py | 9 +++++ tests/_functional/layout.py | 38 ++++++++++++++++++ tests/_functional/pages.py | 15 ++++++- 6 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 tests/_functional/layout.py diff --git a/ordr/resources/__init__.py b/ordr/resources/__init__.py index 65c5e36..8c2780b 100644 --- a/ordr/resources/__init__.py +++ b/ordr/resources/__init__.py @@ -8,6 +8,8 @@ class RootResource: :param pyramid.request.Request request: the current request object ''' + + nav_active = 'welcome' def __init__(self, request): ''' Create the root resource diff --git a/ordr/templates/layout.jinja2 b/ordr/templates/layout.jinja2 index 02b8afc..3b5d874 100644 --- a/ordr/templates/layout.jinja2 +++ b/ordr/templates/layout.jinja2 @@ -3,25 +3,71 @@ - - + + - Ordr2 + {% block title %} + Ordr + {% endblock title %} - + - - {% block content %} -

No content

- {% endblock content %} + + +
+ {% block content %} +

No content

+ {% endblock content %} +
diff --git a/ordr/templates/pages/welcome.jinja2 b/ordr/templates/pages/welcome.jinja2 index f5bc451..a9fab94 100644 --- a/ordr/templates/pages/welcome.jinja2 +++ b/ordr/templates/pages/welcome.jinja2 @@ -1,8 +1,35 @@ {% extends "ordr:templates/layout.jinja2" %} {% block content %} -
-

Ordr

-

Welcome to Ordr, a Pyramid application generated by
Cookiecutter.

+
+
+
+

Welcome to ordr!

+

An order management system to simplify your shopping for laborartory supplies.

+
+
+
+
+
+

Login

+
+
+ +
+
+ +
+ + Forgot your password? +
+
+
+

Register

+

+ Registration is easy as 1-2-3. + Just fill out the form and as soon as your + account has been activated you can start shopping. +

+
{% endblock content %} diff --git a/tests/_functional/__init__.py b/tests/_functional/__init__.py index 6c9c852..3b52226 100644 --- a/tests/_functional/__init__.py +++ b/tests/_functional/__init__.py @@ -13,6 +13,15 @@ WEBTEST_SETTINGS = APP_SETTINGS.copy() class CustomTestApp(webtest.TestApp): ''' might add custom functionality to webtest.TestApp ''' pass + + def login(self, username, password): + ''' stub for user login ''' + self.logout() + pass + + def logout(self): + ''' stub for user logout ''' + pass def create_users(dbsession): diff --git a/tests/_functional/layout.py b/tests/_functional/layout.py new file mode 100644 index 0000000..7cc077f --- /dev/null +++ b/tests/_functional/layout.py @@ -0,0 +1,38 @@ +''' 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 testapp # noqa: F401 + + +def test_navbar_no_user(testapp): # noqa: F811 + result = testapp.get('/faq') + navbar = result.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 result + 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' + ]), + ] + ) +def test_navbar_with_user(testapp, username, password, expected): + 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')] + assert expected == hrefs + assert 'nav-item dropdown' in result diff --git a/tests/_functional/pages.py b/tests/_functional/pages.py index 1901e36..e9164db 100644 --- a/tests/_functional/pages.py +++ b/tests/_functional/pages.py @@ -5,9 +5,20 @@ from . import testapp # noqa: F401 def test_welcome(testapp): # noqa: F811 result = testapp.get('/') - assert 'Ordr' in result + 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 'wrong username' not in result def test_faq(testapp): # noqa: F811 result = testapp.get('/faq') - assert 'FAQ' in result + active = result.html.find('li', class_='active') + assert active.a['href'] == '/faq'