welco/tests/test_manager.py

49 lines
1.5 KiB
Python

# 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 <http://www.gnu.org/licenses/>.
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=/')