Skip to content

Commit 93b0c11

Browse files
committed
updated vars and funcs in input_validator
1 parent d683efa commit 93b0c11

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

splitio/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _make_evaluations(self, key, feature_flags, attributes, method_name, metric_
153153
if input_validator.validate_attributes(attributes, method_name) is False:
154154
return input_validator.generate_control_treatments(feature_flags, method_name)
155155

156-
feature_flags, missing = input_validator.validate_features_get_treatments(
156+
feature_flags, missing = input_validator.validate_feature_flags_get_treatments(
157157
method_name,
158158
feature_flags,
159159
self.ready,

splitio/client/input_validator.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def validate_key(key, method_name):
232232
return matching_key_result, bucketing_key_result
233233

234234

235-
def validate_feature_name(feature_name, should_validate_existance, split_storage, method_name):
235+
def validate_feature_name(feature_flag_name, should_validate_existance, feature_flag_storage, method_name):
236236
"""
237237
Check if feature flag name is valid for get_treatment.
238238
@@ -241,21 +241,21 @@ def validate_feature_name(feature_name, should_validate_existance, split_storage
241241
:return: feature_name
242242
:rtype: str|None
243243
"""
244-
if (not _check_not_null(feature_name, 'feature_name', method_name)) or \
245-
(not _check_is_string(feature_name, 'feature_name', method_name)) or \
246-
(not _check_string_not_empty(feature_name, 'feature_name', method_name)):
244+
if (not _check_not_null(feature_flag_name, 'feature_name', method_name)) or \
245+
(not _check_is_string(feature_flag_name, 'feature_name', method_name)) or \
246+
(not _check_string_not_empty(feature_flag_name, 'feature_name', method_name)):
247247
return None
248248

249-
if should_validate_existance and split_storage.get(feature_name) is None:
249+
if should_validate_existance and feature_flag_storage.get(feature_flag_name) is None:
250250
_LOGGER.warning(
251251
"%s: you passed \"%s\" that does not exist in this environment, "
252252
"please double check what Feature flags exist in the Split user interface.",
253253
method_name,
254-
feature_name
254+
feature_flag_name
255255
)
256256
return None
257257

258-
return _remove_empty_spaces(feature_name, method_name)
258+
return _remove_empty_spaces(feature_flag_name, method_name)
259259

260260

261261
def validate_track_key(key):
@@ -277,16 +277,16 @@ def validate_track_key(key):
277277
return key_str
278278

279279

280-
def validate_traffic_type(traffic_type, should_validate_existance, split_storage):
280+
def validate_traffic_type(traffic_type, should_validate_existance, feature_flag_storage):
281281
"""
282282
Check if traffic_type is valid for track.
283283
284284
:param traffic_type: traffic_type to be checked
285285
:type traffic_type: str
286286
:param should_validate_existance: Whether to check for existante in the feature flag storage.
287287
:type should_validate_existance: bool
288-
:param split_storage: Split storage.
289-
:param split_storage: splitio.storages.SplitStorage
288+
:param feature_flag_storage: Feature flag storage.
289+
:param feature_flag_storage: splitio.storages.SplitStorage
290290
:return: traffic_type
291291
:rtype: str|None
292292
"""
@@ -299,7 +299,7 @@ def validate_traffic_type(traffic_type, should_validate_existance, split_storage
299299
traffic_type)
300300
traffic_type = traffic_type.lower()
301301

302-
if should_validate_existance and not split_storage.is_valid_traffic_type(traffic_type):
302+
if should_validate_existance and not feature_flag_storage.is_valid_traffic_type(traffic_type):
303303
_LOGGER.warning(
304304
'track: Traffic Type %s does not have any corresponding Feature flags in this environment, '
305305
'make sure you\'re tracking your events to a valid traffic type defined '
@@ -344,7 +344,7 @@ def validate_value(value):
344344
return value
345345

346346

347-
def validate_manager_feature_name(feature_name, should_validate_existance, split_storage):
347+
def validate_manager_feature_name(feature_flag_name, should_validate_existance, feature_flag_storage):
348348
"""
349349
Check if feature flag name is valid for track.
350350
@@ -353,76 +353,76 @@ def validate_manager_feature_name(feature_name, should_validate_existance, split
353353
:return: feature_name
354354
:rtype: str|None
355355
"""
356-
if (not _check_not_null(feature_name, 'feature_name', 'split')) or \
357-
(not _check_is_string(feature_name, 'feature_name', 'split')) or \
358-
(not _check_string_not_empty(feature_name, 'feature_name', 'split')):
356+
if (not _check_not_null(feature_flag_name, 'feature_name', 'split')) or \
357+
(not _check_is_string(feature_flag_name, 'feature_name', 'split')) or \
358+
(not _check_string_not_empty(feature_flag_name, 'feature_name', 'split')):
359359
return None
360360

361-
if should_validate_existance and split_storage.get(feature_name) is None:
361+
if should_validate_existance and feature_flag_storage.get(feature_flag_name) is None:
362362
_LOGGER.warning(
363363
"split: you passed \"%s\" that does not exist in this environment, "
364364
"please double check what Feature flags exist in the Split user interface.",
365-
feature_name
365+
feature_flag_name
366366
)
367367
return None
368368

369-
return feature_name
369+
return feature_flag_name
370370

371371

372-
def validate_features_get_treatments( # pylint: disable=invalid-name
372+
def validate_feature_flags_get_treatments( # pylint: disable=invalid-name
373373
method_name,
374-
features,
374+
feature_flags,
375375
should_validate_existance=False,
376-
split_storage=None
376+
feature_flag_storage=None
377377
):
378378
"""
379379
Check if feature flags is valid for get_treatments.
380380
381-
:param features: array of feature flags
382-
:type features: list
383-
:return: filtered_features
381+
:param feature_flags: array of feature flags
382+
:type feature_flags: list
383+
:return: filtered_feature_flags
384384
:rtype: tuple
385385
"""
386-
if features is None or not isinstance(features, list):
386+
if feature_flags is None or not isinstance(feature_flags, list):
387387
_LOGGER.error("%s: feature flag names must be a non-empty array.", method_name)
388388
return None, None
389-
if not features:
389+
if not feature_flags:
390390
_LOGGER.error("%s: feature flag names must be a non-empty array.", method_name)
391391
return None, None
392-
filtered_features = set(
393-
_remove_empty_spaces(feature, method_name) for feature in features
394-
if feature is not None and
395-
_check_is_string(feature, 'feature flag name', method_name) and
396-
_check_string_not_empty(feature, 'feature flag name', method_name)
392+
filtered_feature_flags = set(
393+
_remove_empty_spaces(feature_flag, method_name) for feature_flag in feature_flags
394+
if feature_flag is not None and
395+
_check_is_string(feature_flag, 'feature flag name', method_name) and
396+
_check_string_not_empty(feature_flag, 'feature flag name', method_name)
397397
)
398-
if not filtered_features:
398+
if not filtered_feature_flags:
399399
_LOGGER.error("%s: feature flag names must be a non-empty array.", method_name)
400400
return None, None
401401

402402
if not should_validate_existance:
403-
return filtered_features, []
403+
return filtered_feature_flags, []
404404

405-
valid_missing_features = set(f for f in filtered_features if split_storage.get(f) is None)
406-
for missing_feature in valid_missing_features:
405+
valid_missing_feature_flags = set(f for f in filtered_feature_flags if feature_flag_storage.get(f) is None)
406+
for missing_feature_flag in valid_missing_feature_flags:
407407
_LOGGER.warning(
408408
"%s: you passed \"%s\" that does not exist in this environment, "
409409
"please double check what Feature flags exist in the Split user interface.",
410410
method_name,
411-
missing_feature
411+
missing_feature_flag
412412
)
413-
return filtered_features - valid_missing_features, valid_missing_features
413+
return filtered_feature_flags - valid_missing_feature_flags, valid_missing_feature_flags
414414

415415

416-
def generate_control_treatments(features, method_name):
416+
def generate_control_treatments(feature_flags, method_name):
417417
"""
418418
Generate valid feature flags to control.
419419
420-
:param features: array of feature flags
421-
:type features: list
420+
:param feature_flags: array of feature flags
421+
:type feature_flags: list
422422
:return: dict
423423
:rtype: dict|None
424424
"""
425-
return {feature: (CONTROL, None) for feature in validate_features_get_treatments(method_name, features)[0]}
425+
return {feature_flag: (CONTROL, None) for feature_flag in validate_feature_flags_get_treatments(method_name, feature_flags)[0]}
426426

427427

428428
def validate_attributes(attributes, method_name):
@@ -449,7 +449,7 @@ def filter(self, record):
449449
return record.name not in ('SegmentsAPI', 'HttpClient')
450450

451451

452-
def validate_factory_instantiation(apikey):
452+
def validate_factory_instantiation(sdkkey):
453453
"""
454454
Check if the factory if being instantiated with the appropriate arguments.
455455
@@ -458,11 +458,11 @@ def validate_factory_instantiation(apikey):
458458
:return: bool
459459
:rtype: True|False
460460
"""
461-
if apikey == 'localhost':
461+
if sdkkey == 'localhost':
462462
return True
463-
if (not _check_not_null(apikey, 'apikey', 'factory_instantiation')) or \
464-
(not _check_is_string(apikey, 'apikey', 'factory_instantiation')) or \
465-
(not _check_string_not_empty(apikey, 'apikey', 'factory_instantiation')):
463+
if (not _check_not_null(sdkkey, 'sdkkey', 'factory_instantiation')) or \
464+
(not _check_is_string(sdkkey, 'sdkkey', 'factory_instantiation')) or \
465+
(not _check_string_not_empty(sdkkey, 'sdkkey', 'factory_instantiation')):
466466
return False
467467
return True
468468

tests/client/test_input_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,19 +1156,19 @@ def test_input_validation_factory(self, mocker):
11561156

11571157
assert get_factory(None) is None
11581158
assert logger.error.mock_calls == [
1159-
mocker.call("%s: you passed a null %s, %s must be a non-empty string.", 'factory_instantiation', 'apikey', 'apikey')
1159+
mocker.call("%s: you passed a null %s, %s must be a non-empty string.", 'factory_instantiation', 'sdkkey', 'sdkkey')
11601160
]
11611161

11621162
logger.reset_mock()
11631163
assert get_factory('') is None
11641164
assert logger.error.mock_calls == [
1165-
mocker.call("%s: you passed an empty %s, %s must be a non-empty string.", 'factory_instantiation', 'apikey', 'apikey')
1165+
mocker.call("%s: you passed an empty %s, %s must be a non-empty string.", 'factory_instantiation', 'sdkkey', 'sdkkey')
11661166
]
11671167

11681168
logger.reset_mock()
11691169
assert get_factory(True) is None
11701170
assert logger.error.mock_calls == [
1171-
mocker.call("%s: you passed an invalid %s, %s must be a non-empty string.", 'factory_instantiation', 'apikey', 'apikey')
1171+
mocker.call("%s: you passed an invalid %s, %s must be a non-empty string.", 'factory_instantiation', 'sdkkey', 'sdkkey')
11721172
]
11731173

11741174
logger.reset_mock()

0 commit comments

Comments
 (0)