Skip to content

Commit ac20967

Browse files
Fix lint errors: rename functions and variables to follow snake_case convention
- Rename test functions from camelCase to snake_case: - test_create_user_from_context_with_userId → test_create_user_from_context_with_user_id_attribute - test_create_user_from_context_userId_excluded_when_used → test_create_user_from_context_user_id_attr_excluded_when_used - test_create_user_from_context_invalid_userId_types → test_create_user_from_context_invalid_user_id_attr_types - test_resolve_details_with_userId_priority → test_resolve_details_with_user_id_attr_priority - Rename variables from camelCase to snake_case: - userId → user_id_attr (to avoid confusion with user_id) - Remove unused variable assignments in test_provider.py - Fix whitespace and trailing whitespace issues
1 parent 4c0eee6 commit ac20967

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

devcycle_python_sdk/models/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def create_user_from_context(
124124
raise TargetingKeyMissingError(
125125
"DevCycle: Evaluation context does not contain a valid targeting key, user_id, or userId attribute"
126126
)
127-
127+
128128
if not isinstance(user_id, str):
129129
raise TargetingKeyMissingError(
130130
f"DevCycle: {user_id_source} must be a string, got {type(user_id).__name__}"

test/models/test_user.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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})

test/openfeature_test/test_provider.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def test_resolve_object_details(self):
214214
self.assertDictEqual(details.value, variable_value)
215215
self.assertEqual(details.reason, Reason.TARGETING_MATCH)
216216

217-
def test_resolve_details_with_userId_priority(self):
217+
def test_resolve_details_with_user_id_attr_priority(self):
218218
"""Test that userId is used with proper priority: targeting_key > user_id > userId"""
219219
key = "test-flag"
220220
default_value = False
@@ -228,30 +228,30 @@ def test_resolve_details_with_userId_priority(self):
228228
targeting_key="targeting-key-user",
229229
attributes={"user_id": "user_id-user", "userId": "userId-user"}
230230
)
231-
details = self.provider.resolve_boolean_details(key, default_value, context)
232-
231+
self.provider.resolve_boolean_details(key, default_value, context)
232+
233233
# Verify the call was made with the right user
234234
self.client.variable.assert_called()
235235
called_user = self.client.variable.call_args[1]['user']
236236
self.assertEqual(called_user.user_id, "targeting-key-user")
237-
237+
238238
# Test 2: user_id takes precedence over userId when no targeting_key
239239
context = EvaluationContext(
240240
targeting_key=None,
241241
attributes={"user_id": "user_id-user", "userId": "userId-user"}
242242
)
243-
details = self.provider.resolve_boolean_details(key, default_value, context)
244-
243+
self.provider.resolve_boolean_details(key, default_value, context)
244+
245245
called_user = self.client.variable.call_args[1]['user']
246246
self.assertEqual(called_user.user_id, "user_id-user")
247-
247+
248248
# Test 3: userId is used when no targeting_key or user_id
249249
context = EvaluationContext(
250250
targeting_key=None,
251251
attributes={"userId": "userId-user"}
252252
)
253-
details = self.provider.resolve_boolean_details(key, default_value, context)
254-
253+
self.provider.resolve_boolean_details(key, default_value, context)
254+
255255
called_user = self.client.variable.call_args[1]['user']
256256
self.assertEqual(called_user.user_id, "userId-user")
257257

0 commit comments

Comments
 (0)