tests: add test for wc-base-import
This commit is contained in:
parent
a4b9e56611
commit
25b3f623fc
|
@ -16,7 +16,6 @@
|
|||
|
||||
import functools
|
||||
import json
|
||||
import sys
|
||||
|
||||
from django.db import transaction
|
||||
from django.utils import six
|
||||
|
@ -120,7 +119,6 @@ class Command(BaseCommand):
|
|||
if getattr(oidc_client, key) != locals()[key]:
|
||||
setattr(oidc_client, key, locals()[key])
|
||||
modified = True
|
||||
# FIXME: open_to_all
|
||||
if modified:
|
||||
oidc_client.save()
|
||||
self.info(self.style.SUCCESS('MODIFIED'))
|
||||
|
@ -161,8 +159,10 @@ class Command(BaseCommand):
|
|||
data[string_key] = content_user[string_key]
|
||||
assert 'password' in data
|
||||
assert data['password'].startswith('{SSHA}')
|
||||
data['password'] = 'plonesha1$%s' % data['password']
|
||||
uuid = content_user.get('uuid') or None
|
||||
assert uuid is None or (isinstance(uuid, six.text_type) and uuid), 'invalid uuid %s %s' % (uuid, content_user)
|
||||
assert uuid is None or (isinstance(uuid, six.text_type) and uuid), (
|
||||
'invalid uuid %s %s' % (uuid, content_user))
|
||||
allowed_services = content_user.get('allowed_services', [])
|
||||
assert isinstance(allowed_services, list)
|
||||
|
||||
|
@ -171,12 +171,14 @@ class Command(BaseCommand):
|
|||
self.info('User %s-%s' % (data['username'], uuid), ending=' ')
|
||||
kwargs = {
|
||||
'uuid': uuid,
|
||||
'ou': ou,
|
||||
'defaults': defaults,
|
||||
}
|
||||
else:
|
||||
self.info('User %s' % data['username'], ending=' ')
|
||||
kwargs = {
|
||||
'username': defaults.pop('username'),
|
||||
'ou': ou,
|
||||
'defaults': defaults,
|
||||
}
|
||||
user, created = User.objects.get_or_create(**kwargs)
|
||||
|
|
|
@ -9,3 +9,4 @@ DATABASES = {
|
|||
},
|
||||
}
|
||||
}
|
||||
INSTALLED_APPS += ('authentic2_wallonie_connect',)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# authentic2-wallonie-connect - Authentic2 plugin for the Wallonie Connect usecase
|
||||
# Copyright (C) 2019 Entr'ouvert
|
||||
#
|
||||
|
@ -14,6 +16,48 @@
|
|||
# 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
|
||||
|
||||
def test_empty():
|
||||
pass
|
||||
import json
|
||||
|
||||
from authentic2.a2_rbac.models import OrganizationalUnit as OU
|
||||
from authentic2.custom_user.models import User
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.contrib.auth import authenticate
|
||||
|
||||
|
||||
def test_wc_base_import_command(db, tmpdir):
|
||||
password = 'admin'
|
||||
username = 'user-1'
|
||||
content = {
|
||||
'locality': {
|
||||
'name': 'Liège',
|
||||
'slug': 'liege',
|
||||
},
|
||||
'users': [
|
||||
{
|
||||
'username': 'user-1',
|
||||
'email': 'user-1@example.com',
|
||||
'first_name': 'Jean',
|
||||
'last_name': 'Darmette',
|
||||
'password': '{SSHA}m8eqVfCP2tk1w/g2LT9IvPcOsoBzYWx0',
|
||||
}
|
||||
]
|
||||
}
|
||||
temp_json = tmpdir / 'users.json'
|
||||
with temp_json.open('w') as fd:
|
||||
json.dump(content, fd)
|
||||
|
||||
assert OU.objects.count() == 1
|
||||
assert User.objects.count() == 0
|
||||
call_command('wc-base-import', str(temp_json), no_dry_run=True)
|
||||
assert OU.objects.count() == 2
|
||||
ou = OU.objects.get(slug='liege')
|
||||
assert User.objects.count() == 1
|
||||
user = User.objects.get()
|
||||
assert user.username == username
|
||||
assert user.ou.name == 'Liège'
|
||||
assert user.ou.slug == 'liege'
|
||||
assert user.check_password(password)
|
||||
assert authenticate(username=username, password=password, ou=ou) == user
|
||||
|
|
Loading…
Reference in New Issue