@@ -53,70 +53,70 @@ def test_create_user_from_context_only_user_id(self):
5353 self .assertIsNotNone (user )
5454 self .assertEqual (user .user_id , test_user_id )
5555
56- def test_create_user_from_context_with_userId (self ):
56+ def test_create_user_from_context_with_user_id_attribute (self ):
5757 test_user_id = "userId-12345"
58-
58+
5959 # Test userId as the only user ID source
6060 context = EvaluationContext (
6161 targeting_key = None , attributes = {"userId" : test_user_id }
6262 )
6363 user = DevCycleUser .create_user_from_context (context )
6464 self .assertIsNotNone (user )
6565 self .assertEqual (user .user_id , test_user_id )
66-
66+
6767 # Test that userId is excluded from custom data when used as user ID
6868 self .assertIsNone (user .customData )
6969
7070 def test_create_user_from_context_user_id_priority (self ):
7171 targeting_key_id = "targeting-12345"
7272 user_id = "user_id-12345"
73- userId = "userId-12345"
74-
73+ user_id_attr = "userId-12345"
74+
7575 # Test targeting_key takes precedence over user_id and userId
7676 context = EvaluationContext (
77- targeting_key = targeting_key_id ,
78- attributes = {"user_id" : user_id , "userId" : userId }
77+ targeting_key = targeting_key_id ,
78+ attributes = {"user_id" : user_id , "userId" : user_id_attr }
7979 )
8080 user = DevCycleUser .create_user_from_context (context )
8181 self .assertEqual (user .user_id , targeting_key_id )
82-
82+
8383 # Test user_id takes precedence over userId
8484 context = EvaluationContext (
85- targeting_key = None ,
86- attributes = {"user_id" : user_id , "userId" : userId }
85+ targeting_key = None ,
86+ attributes = {"user_id" : user_id , "userId" : user_id_attr }
8787 )
8888 user = DevCycleUser .create_user_from_context (context )
8989 self .assertEqual (user .user_id , user_id )
90-
90+
9191 # Test userId is used when targeting_key and user_id are not available
9292 context = EvaluationContext (
93- targeting_key = None ,
94- attributes = {"userId" : userId }
93+ targeting_key = None ,
94+ attributes = {"userId" : user_id_attr }
9595 )
9696 user = DevCycleUser .create_user_from_context (context )
97- self .assertEqual (user .user_id , userId )
97+ self .assertEqual (user .user_id , user_id_attr )
9898
9999 def test_create_user_from_context_user_id_fields_always_excluded (self ):
100100 targeting_key_id = "targeting-12345"
101- userId = "userId-12345"
101+ user_id_attr = "userId-12345"
102102 user_id = "user_id-12345"
103-
103+
104104 # When targeting_key is used, both user_id and userId should be excluded from custom data
105105 context = EvaluationContext (
106- targeting_key = targeting_key_id ,
107- attributes = {"user_id" : user_id , "userId" : userId , "other_field" : "value" }
106+ targeting_key = targeting_key_id ,
107+ attributes = {"user_id" : user_id , "userId" : user_id_attr , "other_field" : "value" }
108108 )
109109 user = DevCycleUser .create_user_from_context (context )
110110 self .assertEqual (user .user_id , targeting_key_id )
111111 self .assertIsNotNone (user .customData )
112112 self .assertNotIn ("user_id" , user .customData )
113113 self .assertNotIn ("userId" , user .customData )
114114 self .assertEqual (user .customData ["other_field" ], "value" )
115-
115+
116116 # When user_id is used, userId should still be excluded from custom data
117117 context = EvaluationContext (
118- targeting_key = None ,
119- attributes = {"user_id" : user_id , "userId" : userId , "other_field" : "value" }
118+ targeting_key = None ,
119+ attributes = {"user_id" : user_id , "userId" : user_id_attr , "other_field" : "value" }
120120 )
121121 user = DevCycleUser .create_user_from_context (context )
122122 self .assertEqual (user .user_id , user_id )
@@ -127,10 +127,10 @@ def test_create_user_from_context_user_id_fields_always_excluded(self):
127127
128128 def test_create_user_from_context_targeting_key_excluded_from_attributes (self ):
129129 targeting_key_id = "targeting-12345"
130-
130+
131131 # When targeting_key appears in attributes, it should be excluded from custom data
132132 context = EvaluationContext (
133- targeting_key = targeting_key_id ,
133+ targeting_key = targeting_key_id ,
134134 attributes = {"targeting_key" : "should-be-excluded" , "other_field" : "value" }
135135 )
136136 user = DevCycleUser .create_user_from_context (context )
@@ -139,32 +139,32 @@ def test_create_user_from_context_targeting_key_excluded_from_attributes(self):
139139 self .assertNotIn ("targeting_key" , user .customData )
140140 self .assertEqual (user .customData ["other_field" ], "value" )
141141
142- def test_create_user_from_context_userId_excluded_when_used (self ):
143- userId = "userId-12345"
144-
142+ def test_create_user_from_context_user_id_attr_excluded_when_used (self ):
143+ user_id_attr = "userId-12345"
144+
145145 # When userId is used as user ID, it should be excluded from custom data
146146 context = EvaluationContext (
147- targeting_key = None ,
148- attributes = {"userId" : userId , "other_field" : "value" }
147+ targeting_key = None ,
148+ attributes = {"userId" : user_id_attr , "other_field" : "value" }
149149 )
150150 user = DevCycleUser .create_user_from_context (context )
151- self .assertEqual (user .user_id , userId )
151+ self .assertEqual (user .user_id , user_id_attr )
152152 self .assertIsNotNone (user .customData )
153153 self .assertNotIn ("userId" , user .customData )
154154 self .assertEqual (user .customData ["other_field" ], "value" )
155155
156- def test_create_user_from_context_invalid_userId_types (self ):
156+ def test_create_user_from_context_invalid_user_id_attr_types (self ):
157157 # Test non-string userId values are ignored and cause error
158158 with self .assertRaises (TargetingKeyMissingError ):
159159 DevCycleUser .create_user_from_context (
160160 EvaluationContext (targeting_key = None , attributes = {"userId" : 12345 })
161161 )
162-
162+
163163 with self .assertRaises (TargetingKeyMissingError ):
164164 DevCycleUser .create_user_from_context (
165165 EvaluationContext (targeting_key = None , attributes = {"userId" : None })
166166 )
167-
167+
168168 with self .assertRaises (TargetingKeyMissingError ):
169169 DevCycleUser .create_user_from_context (
170170 EvaluationContext (targeting_key = None , attributes = {"userId" : True })
0 commit comments