diff --git a/tests/test_manager.py b/tests/test_manager.py new file mode 100644 index 0000000..49db243 --- /dev/null +++ b/tests/test_manager.py @@ -0,0 +1,48 @@ +# welco - multichannel request processing +# Copyright (C) 2020 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +import pytest + +def login(app, username='toto', password='toto'): + login_page = app.get('/login/') + login_form = login_page.forms[0] + login_form['username'] = username + login_form['password'] = password + resp = login_form.submit() + assert resp.status_int == 302 + return app + + +@pytest.fixture +def logged_app(app, user): + return login(app) + + +def test_unlogged_access(app): + # connect while not being logged in + assert app.get('/', status=302).location.endswith('/login/?next=/') + + +def test_access(logged_app, mail_group): + resp = logged_app.get('/', status=302) + assert resp.location == 'mail/' + + +def test_logout(logged_app): + app = logged_app + app.get('/logout/') + assert app.get('/', status=302).location.endswith('/login/?next=/') diff --git a/welco/templates/welco/login.html b/welco/templates/welco/login.html new file mode 100644 index 0000000..9718ac1 --- /dev/null +++ b/welco/templates/welco/login.html @@ -0,0 +1,10 @@ +{% extends "welco/base.html" %} +{% load i18n %} + +{% block content %} +
+ {% csrf_token %} + {{ form }} + +
+{% endblock %} diff --git a/welco/views.py b/welco/views.py index 62768bc..db06010 100644 --- a/welco/views.py +++ b/welco/views.py @@ -53,7 +53,7 @@ def login(request, *args, **kwargs): return HttpResponseRedirect(resolve_url('mellon_login')) return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))) - return auth_views.login(request, *args, **kwargs) + return auth_views.login(request, template_name='welco/login.html') def logout(request, next_page=None): if any(get_idps()):