Skip to content

Commit

Permalink
fix: store tags and add unit test for tags and new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Oct 18, 2024
1 parent cd4b351 commit 2286fd5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fence/resources/admin/admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions tests/admin/test_admin_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2286fd5

Please sign in to comment.