diff --git a/fence/resources/admin/admin_users.py b/fence/resources/admin/admin_users.py index 298b2e2aa2..956da6cd7d 100644 --- a/fence/resources/admin/admin_users.py +++ b/fence/resources/admin/admin_users.py @@ -13,6 +13,7 @@ UserGoogleAccountToProxyGroup, query_for_user, IdentityProvider, + Tag, ) from fence.resources import group as gp, project as pj, user as us, userdatamodel as udm from flask import current_app as capp @@ -152,7 +153,9 @@ def create_user( usr.identity_provider = idp if tags: logger.debug(f"Setting {len(tags)} tags for user {username}...") - usr.tags.extend(tags) + for key, value in tags.items(): + tag = Tag(key=key, value=value) + usr.tags.append(tag) logger.debug(f"Adding user {username}...") current_session.add(usr) diff --git a/tests/admin/test_admin_users.py b/tests/admin/test_admin_users.py index 44fbf01f78..2068dd3407 100644 --- a/tests/admin/test_admin_users.py +++ b/tests/admin/test_admin_users.py @@ -30,6 +30,35 @@ def test_create_user(db_session, oauth_client): assert user.username == "insert_user" assert user.is_admin == True assert user.email == "insert_user@fake.com" + assert user.display_name is None + assert user.phone_number is None + assert user.identity_provider is None + assert len(user.tags) == 0 + + +def test_create_user_with_all_fields_set(db_session, oauth_client): + adm.create_user( + db_session, + "insert_user", + None, + "insert_user@fake.com", + "Dummy Name", + "+310000", + "fakeIDP", + {"key1": "value1", "key2": "value2"}, + ) + user = db_session.query(User).filter(User.username == "insert_user").first() + assert user.username == "insert_user" + assert user.is_admin == False + assert user.email == "insert_user@fake.com" + assert user.display_name == "Dummy Name" + assert user.phone_number == "+310000" + assert user.identity_provider.name == "fakeIDP" + assert len(user.tags) == 2 + assert user.tags[0].key == "key1" + assert user.tags[0].value == "value1" + assert user.tags[1].key == "key2" + assert user.tags[1].value == "value2" def test_delete_user(db_session, awg_users, cloud_manager):