Skip to content

Commit ba4841c

Browse files
CopilotSubterrane
andcommitted
Fix manager_user_id field validation by changing type from StrictInt to StrictStr
Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
1 parent e9ca23c commit ba4841c

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

onelogin/models/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class User(BaseModel):
3737
directory_id: Optional[StrictInt] = Field(None, description="The ID of the OneLogin Directory of the user.")
3838
trusted_idp_id: Optional[StrictInt] = Field(None, description="The ID of the OneLogin Trusted IDP of the user.")
3939
manager_ad_id: Optional[StrictStr] = Field(None, description="The ID of the user's manager in Active Directory.")
40-
manager_user_id: Optional[StrictInt] = Field(None, description="The OneLogin User ID for the user's manager.")
40+
manager_user_id: Optional[StrictStr] = Field(None, description="The OneLogin User ID for the user's manager.")
4141
samaccountname: Optional[StrictStr] = Field(None, description="The user's Active Directory username.")
4242
member_of: Optional[StrictStr] = Field(None, description="The user's directory membership.")
4343
userprincipalname: Optional[StrictStr] = Field(None, description="The principle name of the user.")
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# coding: utf-8
2+
3+
"""
4+
OneLogin API
5+
6+
OpenAPI Specification for OneLogin # noqa: E501
7+
8+
The version of the OpenAPI document: 3.1.1
9+
Generated by OpenAPI Generator (https://openapi-generator.tech)
10+
11+
Do not edit the class manually.
12+
"""
13+
14+
15+
import unittest
16+
import datetime
17+
18+
import onelogin
19+
from onelogin.models.user import User # noqa: E501
20+
from onelogin.rest import ApiException
21+
22+
23+
class TestUserManagerUserIdFix(unittest.TestCase):
24+
"""Test case for manager_user_id field fix (GitHub issue #100)"""
25+
26+
def setUp(self):
27+
pass
28+
29+
def tearDown(self):
30+
pass
31+
32+
def test_manager_user_id_with_string_value(self):
33+
"""
34+
Test that manager_user_id accepts string values from API response.
35+
This test validates the fix for GitHub issue #100 where API returns
36+
manager_user_id as string but model expected integer.
37+
"""
38+
user_data = {
39+
"id": 123,
40+
"username": "testuser",
41+
"email": "test@example.com",
42+
"manager_user_id": "252462756" # String value as returned by API
43+
}
44+
45+
# This should work without validation errors
46+
user = User.from_dict(user_data)
47+
self.assertEqual(user.manager_user_id, "252462756")
48+
self.assertIsInstance(user.manager_user_id, str)
49+
50+
def test_manager_user_id_with_none_value(self):
51+
"""
52+
Test that manager_user_id accepts None values.
53+
"""
54+
user_data = {
55+
"id": 123,
56+
"username": "testuser",
57+
"email": "test@example.com",
58+
"manager_user_id": None
59+
}
60+
61+
user = User.from_dict(user_data)
62+
self.assertIsNone(user.manager_user_id)
63+
64+
def test_manager_user_id_missing_field(self):
65+
"""
66+
Test that manager_user_id can be omitted (defaults to None).
67+
"""
68+
user_data = {
69+
"id": 123,
70+
"username": "testuser",
71+
"email": "test@example.com"
72+
# manager_user_id field is omitted
73+
}
74+
75+
user = User.from_dict(user_data)
76+
self.assertIsNone(user.manager_user_id)
77+
78+
def test_user_serialization_with_manager_user_id(self):
79+
"""
80+
Test that User can be serialized back to dict with manager_user_id.
81+
"""
82+
user_data = {
83+
"id": 123,
84+
"username": "testuser",
85+
"email": "test@example.com",
86+
"manager_user_id": "252462756"
87+
}
88+
89+
user = User.from_dict(user_data)
90+
user_dict = user.to_dict()
91+
92+
self.assertEqual(user_dict["manager_user_id"], "252462756")
93+
self.assertIsInstance(user_dict["manager_user_id"], str)
94+
95+
def test_parse_obj_compatibility(self):
96+
"""
97+
Test that parse_obj method (used in API deserialization) works correctly.
98+
This specifically tests the flow mentioned in the original issue traceback.
99+
"""
100+
user_data = {
101+
"id": 123,
102+
"username": "testuser",
103+
"email": "test@example.com",
104+
"manager_user_id": "252462756"
105+
}
106+
107+
# This is the method called in the traceback from the original issue
108+
user = User.parse_obj(user_data)
109+
self.assertEqual(user.manager_user_id, "252462756")
110+
self.assertIsInstance(user.manager_user_id, str)
111+
112+
113+
if __name__ == '__main__':
114+
unittest.main()

0 commit comments

Comments
 (0)