Skip to content

Commit 714b4ba

Browse files
committed
updated evaluator
1 parent 34f66ae commit 714b4ba

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

splitio/engine/evaluator.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ def eval_with_context(self, key, bucketing, feature_name, attrs, ctx):
7474
}
7575

7676
def _get_fallback_treatment_and_label(self, feature_name, treatment, label):
77-
if self._fallback_treatments_configuration == None or self._fallback_treatments_configuration.fallback_config == None:
77+
if self._fallback_treatments_configuration == None:
7878
return label, treatment, None
7979

80-
if self._fallback_treatments_configuration.fallback_config.by_flag_fallback_treatment != None and \
81-
self._fallback_treatments_configuration.fallback_config.by_flag_fallback_treatment.get(feature_name) != None:
80+
if self._fallback_treatments_configuration.by_flag_fallback_treatment != None and \
81+
self._fallback_treatments_configuration.by_flag_fallback_treatment.get(feature_name) != None:
8282
_LOGGER.debug('Using Fallback Treatment for feature: %s', feature_name)
83-
return self._fallback_treatments_configuration.fallback_config.by_flag_fallback_treatment.get(feature_name).label_prefix + label, \
84-
self._fallback_treatments_configuration.fallback_config.by_flag_fallback_treatment.get(feature_name).treatment, \
85-
self._fallback_treatments_configuration.fallback_config.by_flag_fallback_treatment.get(feature_name).config
83+
return self._fallback_treatments_configuration.by_flag_fallback_treatment.get(feature_name).label_prefix + label, \
84+
self._fallback_treatments_configuration.by_flag_fallback_treatment.get(feature_name).treatment, \
85+
self._fallback_treatments_configuration.by_flag_fallback_treatment.get(feature_name).config
8686

87-
if self._fallback_treatments_configuration.fallback_config.global_fallback_treatment != None:
87+
if self._fallback_treatments_configuration.global_fallback_treatment != None:
8888
_LOGGER.debug('Using Global Fallback Treatment.')
89-
return self._fallback_treatments_configuration.fallback_config.global_fallback_treatment.label_prefix + label, \
90-
self._fallback_treatments_configuration.fallback_config.global_fallback_treatment.treatment, \
91-
self._fallback_treatments_configuration.fallback_config.global_fallback_treatment.config
89+
return self._fallback_treatments_configuration.global_fallback_treatment.label_prefix + label, \
90+
self._fallback_treatments_configuration.global_fallback_treatment.treatment, \
91+
self._fallback_treatments_configuration.global_fallback_treatment.config
9292

9393
return label, treatment, None
9494

tests/engine/test_evaluator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from splitio.models.grammar import condition
1313
from splitio.models import rule_based_segments
1414
from splitio.models.fallback_treatment import FallbackTreatment
15-
from splitio.models.fallback_config import FallbackConfig, FallbackTreatmentsConfiguration
15+
from splitio.models.fallback_config import FallbackTreatmentsConfiguration
1616
from splitio.engine import evaluator, splitters
1717
from splitio.engine.evaluator import EvaluationContext
1818
from splitio.storage.inmemmory import InMemorySplitStorage, InMemorySegmentStorage, InMemoryRuleBasedSegmentStorage, \
@@ -384,7 +384,7 @@ def test_evaluate_treatment_with_fallback(self, mocker):
384384

385385
# should use global fallback
386386
logger_mock.reset_mock()
387-
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment("off-global", {"prop":"val"}))))
387+
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackTreatment("off-global", {"prop":"val"})))
388388
result = e.eval_with_context('some_key', 'some_bucketing_key', 'some2', {}, ctx)
389389
assert result['treatment'] == 'off-global'
390390
assert result['configurations'] == '{"prop": "val"}'
@@ -394,29 +394,29 @@ def test_evaluate_treatment_with_fallback(self, mocker):
394394

395395
# should use by flag fallback
396396
logger_mock.reset_mock()
397-
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackConfig(None, {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})})))
397+
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(None, {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})}))
398398
result = e.eval_with_context('some_key', 'some_bucketing_key', 'some2', {}, ctx)
399399
assert result['treatment'] == 'off-some2'
400400
assert result['configurations'] == '{"prop2": "val2"}'
401401
assert result['impression']['label'] == "fallback - " + Label.SPLIT_NOT_FOUND
402402
assert logger_mock.debug.mock_calls[0] == mocker.call("Using Fallback Treatment for feature: %s", "some2")
403403

404404
# should not use any fallback
405-
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackConfig(None, {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})})))
405+
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(None, {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})}))
406406
result = e.eval_with_context('some_key', 'some_bucketing_key', 'some3', {}, ctx)
407407
assert result['treatment'] == 'control'
408408
assert result['configurations'] == None
409409
assert result['impression']['label'] == Label.SPLIT_NOT_FOUND
410410

411411
# should use by flag fallback
412-
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment("off-global", {"prop":"val"}), {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})})))
412+
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackTreatment("off-global", {"prop":"val"}), {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})}))
413413
result = e.eval_with_context('some_key', 'some_bucketing_key', 'some2', {}, ctx)
414414
assert result['treatment'] == 'off-some2'
415415
assert result['configurations'] == '{"prop2": "val2"}'
416416
assert result['impression']['label'] == "fallback - " + Label.SPLIT_NOT_FOUND
417417

418418
# should global flag fallback
419-
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackConfig(FallbackTreatment("off-global", {"prop":"val"}), {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})})))
419+
e = evaluator.Evaluator(splitter_mock, FallbackTreatmentsConfiguration(FallbackTreatment("off-global", {"prop":"val"}), {"some2": FallbackTreatment("off-some2", {"prop2":"val2"})}))
420420
result = e.eval_with_context('some_key', 'some_bucketing_key', 'some3', {}, ctx)
421421
assert result['treatment'] == 'off-global'
422422
assert result['configurations'] == '{"prop": "val"}'

0 commit comments

Comments
 (0)