From 76a2bbcdd89f789887211bd8e2ee51e316a1d360 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 15 Jun 2017 17:33:17 +0200 Subject: [PATCH] agent: use BaseUserSerializer for user provisionning (fixes #16924) --- hobo/agent/authentic2/provisionning.py | 4 ++-- tests_authentic/test_provisionning.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hobo/agent/authentic2/provisionning.py b/hobo/agent/authentic2/provisionning.py index 6f481a8..ab9cbd2 100644 --- a/hobo/agent/authentic2/provisionning.py +++ b/hobo/agent/authentic2/provisionning.py @@ -74,6 +74,7 @@ class Provisionning(object): if mode == 'provision': def user_to_json(service, user, user_roles): + from authentic2.api_views import BaseUserSerializer data = {} roles = user.roles_and_parents().prefetch_related('attributes') data.update({ @@ -89,8 +90,7 @@ class Provisionning(object): 'slug': role.slug, } for role in roles], }) - for av in user.attribute_values.all(): - data[str(av.attribute.name)] = av.to_python() + data.update(BaseUserSerializer(user).data) # check if user is superuser through a role role_is_superuser = False if service: diff --git a/tests_authentic/test_provisionning.py b/tests_authentic/test_provisionning.py index d98367d..d0ee222 100644 --- a/tests_authentic/test_provisionning.py +++ b/tests_authentic/test_provisionning.py @@ -164,7 +164,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert len(data) == 2 assert len(set([o['uuid'] for o in data])) == 2 for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', 'is_superuser', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] in users user = users[o['uuid']] @@ -203,7 +203,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert isinstance(data, list) assert len(data) == 2 for o, user in zip(data, [user1, user2]): - assert set(o.keys()) <= set(['code_postal', 'uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['code_postal', 'uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] == user.uuid assert o['username'] == user.username @@ -212,7 +212,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert o['email'] == user.email assert o['roles'] == [{'name': r.name, 'slug': r.slug, 'uuid': r.uuid} for r in user.roles.all()] - assert 'code_postal' not in o or o['code_postal'] == '13400' + assert o['code_postal'] is None or o['code_postal'] == '13400' assert o['is_superuser'] is user.is_superuser notify_agents.reset_mock() @@ -239,7 +239,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert isinstance(data, list) assert len(data) == 1 for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] == user1.uuid assert o['username'] == user1.username @@ -279,7 +279,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert len(data) == 1 print data for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] in users user = users[o['uuid']] @@ -318,7 +318,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert isinstance(data, list) assert len(data) == 1 for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] == user1.uuid assert o['username'] == user1.username @@ -353,7 +353,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert isinstance(data, list) assert len(data) == 1 for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] == user1.uuid assert o['username'] == user1.username @@ -400,7 +400,7 @@ def test_provision_user(transactional_db, tenant, caplog): assert isinstance(data, list) assert len(data) == 1 for o in data: - assert set(o.keys()) == set(['uuid', 'username', 'first_name', + assert set(o.keys()) >= set(['uuid', 'username', 'first_name', 'is_superuser', 'last_name', 'email', 'roles']) assert o['uuid'] == user1.uuid assert o['username'] == user1.username -- 2.1.4