diff --git a/docs/User.md b/docs/User.md index 93f5d27f..f1e4687b 100644 --- a/docs/User.md +++ b/docs/User.md @@ -40,6 +40,7 @@ Name | Type | Description | Notes **password_confirmation** | **str** | Required if the password is being set. | [optional] **password_algorithm** | **str** | Use this when importing a password that's already hashed. Prepend the salt value to the cleartext password value before SHA-256-encoding it | [optional] **salt** | **str** | The salt value used with the password_algorithm. | [optional] +**custom_attributes** | **Dict[str, Any]** | Custom user attributes defined in your OneLogin account. | [optional] ## Example diff --git a/onelogin/models/user.py b/onelogin/models/user.py index e9dde0e5..22a078b2 100644 --- a/onelogin/models/user.py +++ b/onelogin/models/user.py @@ -13,7 +13,7 @@ import json -from typing import List, Optional +from typing import Any, Dict, List, Optional from pydantic import BaseModel, Field, StrictInt, StrictStr, conlist, field_validator class User(BaseModel): @@ -56,7 +56,8 @@ class User(BaseModel): password_confirmation: Optional[StrictStr] = Field(None, description="Required if the password is being set.") password_algorithm: Optional[StrictStr] = Field(None, description="Use this when importing a password that's already hashed. Prepend the salt value to the cleartext password value before SHA-256-encoding it") salt: Optional[StrictStr] = Field(None, description="The salt value used with the password_algorithm.") - __properties = ["id", "username", "email", "firstname", "lastname", "title", "department", "company", "comment", "group_id", "role_ids", "phone", "state", "status", "directory_id", "trusted_idp_id", "manager_ad_id", "manager_user_id", "samaccountname", "member_of", "userprincipalname", "distinguished_name", "external_id", "activated_at", "last_login", "invitation_sent_at", "updated_at", "preferred_locale_code", "created_at", "invalid_login_attempts", "locked_until", "password_changed_at", "password", "password_confirmation", "password_algorithm", "salt"] + custom_attributes: Optional[Dict[str, Any]] = Field(None, description="Custom user attributes defined in your OneLogin account.") + __properties = ["id", "username", "email", "firstname", "lastname", "title", "department", "company", "comment", "group_id", "role_ids", "phone", "state", "status", "directory_id", "trusted_idp_id", "manager_ad_id", "manager_user_id", "samaccountname", "member_of", "userprincipalname", "distinguished_name", "external_id", "activated_at", "last_login", "invitation_sent_at", "updated_at", "preferred_locale_code", "created_at", "invalid_login_attempts", "locked_until", "password_changed_at", "password", "password_confirmation", "password_algorithm", "salt", "custom_attributes"] @field_validator('state') @classmethod @@ -153,7 +154,8 @@ def from_dict(cls, obj: dict) -> User: "password": obj.get("password"), "password_confirmation": obj.get("password_confirmation"), "password_algorithm": obj.get("password_algorithm"), - "salt": obj.get("salt") + "salt": obj.get("salt"), + "custom_attributes": obj.get("custom_attributes") }) return _obj diff --git a/test/test_user_custom_attributes.py b/test/test_user_custom_attributes.py new file mode 100644 index 00000000..b764d0bf --- /dev/null +++ b/test/test_user_custom_attributes.py @@ -0,0 +1,119 @@ +# coding: utf-8 + +""" + OneLogin API + + Test for custom_attributes support in User model + + The version of the OpenAPI document: 3.1.1 +""" + + +import unittest +import json + +import onelogin +from onelogin.models.user import User +from onelogin.rest import ApiException + + +class TestUserCustomAttributes(unittest.TestCase): + """User custom_attributes unit test""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_user_with_custom_attributes(self): + """Test User with custom_attributes""" + # Create a user with custom_attributes + user_data = { + "id": 123, + "username": "test_user", + "email": "test@example.com", + "firstname": "Test", + "lastname": "User", + "custom_attributes": { + "department_code": "ENG001", + "employee_id": "12345", + "cost_center": "CC-100" + } + } + + # Test from_dict + user = User.from_dict(user_data) + + # Verify basic fields + self.assertEqual(user.id, 123) + self.assertEqual(user.username, "test_user") + self.assertEqual(user.email, "test@example.com") + self.assertEqual(user.firstname, "Test") + self.assertEqual(user.lastname, "User") + + # Verify custom_attributes + self.assertIsNotNone(user.custom_attributes) + self.assertIsInstance(user.custom_attributes, dict) + self.assertEqual(user.custom_attributes.get("department_code"), "ENG001") + self.assertEqual(user.custom_attributes.get("employee_id"), "12345") + self.assertEqual(user.custom_attributes.get("cost_center"), "CC-100") + + def test_user_without_custom_attributes(self): + """Test User without custom_attributes""" + user_data = { + "id": 456, + "username": "test_user2", + "email": "test2@example.com" + } + + user = User.from_dict(user_data) + + self.assertEqual(user.id, 456) + self.assertEqual(user.username, "test_user2") + self.assertIsNone(user.custom_attributes) + + def test_user_to_dict_with_custom_attributes(self): + """Test User to_dict with custom_attributes""" + user = User( + id=789, + username="test_user3", + email="test3@example.com", + custom_attributes={ + "location": "San Francisco", + "employee_type": "Full-time" + } + ) + + user_dict = user.to_dict() + + self.assertEqual(user_dict["id"], 789) + self.assertEqual(user_dict["username"], "test_user3") + self.assertEqual(user_dict["email"], "test3@example.com") + self.assertIn("custom_attributes", user_dict) + self.assertEqual(user_dict["custom_attributes"]["location"], "San Francisco") + self.assertEqual(user_dict["custom_attributes"]["employee_type"], "Full-time") + + def test_user_from_json_with_custom_attributes(self): + """Test User from_json with custom_attributes""" + json_str = '''{ + "id": 999, + "username": "test_user4", + "email": "test4@example.com", + "custom_attributes": { + "badge_number": "B12345", + "clearance_level": "Level 2" + } + }''' + + user = User.from_json(json_str) + + self.assertEqual(user.id, 999) + self.assertEqual(user.username, "test_user4") + self.assertIsNotNone(user.custom_attributes) + self.assertEqual(user.custom_attributes.get("badge_number"), "B12345") + self.assertEqual(user.custom_attributes.get("clearance_level"), "Level 2") + + +if __name__ == '__main__': + unittest.main()