diff --git a/ordr/templates/layout.jinja2 b/ordr/templates/layout.jinja2
index 3b5d874..35c0138 100644
--- a/ordr/templates/layout.jinja2
+++ b/ordr/templates/layout.jinja2
@@ -24,7 +24,7 @@
ordr
{% if not request.user %}
- -
+
-
Welcome
-
diff --git a/ordr/views/pages.py b/ordr/views/pages.py
index 61f1c11..e20b733 100644
--- a/ordr/views/pages.py
+++ b/ordr/views/pages.py
@@ -1,3 +1,4 @@
+from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config
@@ -7,6 +8,18 @@ from pyramid.view import view_config
renderer='ordr:templates/pages/welcome.jinja2',
)
def welcome(context, request):
+ next = 'orders' if request.user else 'login'
+ redirect_to = request.resource_url(context, next)
+ return HTTPFound(redirect_to)
+
+
+@view_config(
+ context='ordr.resources.RootResource',
+ name='login',
+ permission='view',
+ renderer='ordr:templates/pages/welcome.jinja2',
+ )
+def login(context, request):
return {}
diff --git a/tests/_functional/pages.py b/tests/_functional/pages.py
index e9164db..24558f5 100644
--- a/tests/_functional/pages.py
+++ b/tests/_functional/pages.py
@@ -1,10 +1,21 @@
''' functional tests for ordr2.views.pages '''
+import pytest
+
from . import testapp # noqa: F401
+@pytest.mark.xfail
def test_welcome(testapp): # noqa: F811
+ testapp.logout()
result = testapp.get('/')
+ assert result.location == 'http://localhost/login'
+ testapp.login('user', 'password')
+ assert result.location == 'http://localhost/orders'
+
+
+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'}
diff --git a/tests/views/pages.py b/tests/views/pages.py
index 82547b5..69b9e7c 100644
--- a/tests/views/pages.py
+++ b/tests/views/pages.py
@@ -1,9 +1,19 @@
+import pytest
+from pyramid.httpexceptions import HTTPFound
+from pyramid.testing import DummyRequest
-def test_welcome():
+
+@pytest.mark.parametrize(
+ 'user,location',
+ [(None, '/login'), ('someone', '/orders')]
+ )
+def test_welcome(user, location):
from ordr.views.pages import welcome
- result = welcome(None, None)
- assert result == {}
+ request = DummyRequest(user=user)
+ result = welcome(None, request)
+ assert isinstance(result, HTTPFound)
+ assert result.location == f'http://example.com/{location}'
def test_faq():