authentic/tests/test_admin.py

97 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
# authentic2 - versatile identity manager
# Copyright (C) 2010-2019 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/>.
from __future__ import unicode_literals
from urllib.parse import urlparse
from authentic2.custom_user.models import User
from authentic2.models import Attribute
from . import utils
def test_user_admin(db, app, superuser):
utils.login(app, superuser)
Attribute.objects.create(
label='SIRET',
name='siret',
kind='string',
required=False,
user_visible=True,
user_editable=False,
asked_on_registration=False,
multiple=False,
)
Attribute.objects.create(
label='Civilité',
name='civilite',
kind='title',
required=False,
user_visible=True,
user_editable=True,
asked_on_registration=True,
multiple=False,
)
superuser.verified_attributes.first_name = 'John'
superuser.verified_attributes.last_name = 'Doe'
resp = app.get('/admin/custom_user/user/%s/' % superuser.pk).maybe_follow()
assert set(resp.form.fields.keys()) >= set(
[
'username',
'first_name',
'last_name',
'civilite',
'siret',
'is_staff',
'is_superuser',
'ou',
'groups',
'date_joined_0',
'date_joined_1',
'last_login_0',
'last_login_1',
]
)
resp.form.set('first_name', 'John')
resp.form.set('last_name', 'Doe')
resp.form.set('civilite', 'Mr')
resp.form.set('siret', '1234')
resp = resp.form.submit('_continue').follow()
modified_admin = User.objects.get(pk=superuser.pk)
assert modified_admin.first_name == 'John'
assert modified_admin.last_name == 'Doe'
assert modified_admin.attributes.civilite == 'Mr'
assert modified_admin.attributes.siret == '1234'
def test_attributes_admin(db, app, superuser):
utils.login(app, superuser)
resp = app.get('/admin/authentic2/attribute/')
resp = resp.click('First name')
def test_app_setting_login_url(app, db, settings):
settings.A2_MANAGER_LOGIN_URL = '/other-login/'
response = app.get('/admin/')
assert urlparse(response['Location']).path == '/admin/login/'
response = response.follow()
assert urlparse(response['Location']).path == settings.A2_MANAGER_LOGIN_URL
assert urlparse(response['Location']).query == 'next=/admin/'