diff --git a/optimizely/entities.py b/optimizely/entities.py index 4960e27e..15576568 100644 --- a/optimizely/entities.py +++ b/optimizely/entities.py @@ -74,6 +74,23 @@ def get_audience_conditions_or_ids(self): def __str__(self): return self.key + @staticmethod + def get_default(): + """ returns an empty experiment object. """ + experiment = Experiment( + id='', + key='', + layerId='', + status='', + variations=[], + trafficAllocation=[], + audienceIds=[], + audienceConditions=[], + forcedVariations={} + ) + + return experiment + class FeatureFlag(BaseEntity): def __init__(self, id, key, experimentIds, rolloutId, variables, groupId=None, **kwargs): diff --git a/optimizely/optimizely.py b/optimizely/optimizely.py index 5d819915..04b057f7 100644 --- a/optimizely/optimizely.py +++ b/optimizely/optimizely.py @@ -199,17 +199,7 @@ def _send_impression_event(self, project_config, experiment, variation, flag_key attributes: Dict representing user attributes and values which need to be recorded. """ if not experiment: - experiment = entities.Experiment( - id='', - key='', - layerId='', - status='', - variations=[], - trafficAllocation=[], - audienceIds=[], - audienceConditions=[], - forcedVariations={} - ) + experiment = entities.Experiment.get_default() variation_id = variation.id if variation is not None else None user_event = user_event_factory.UserEventFactory.create_impression_event( diff --git a/tests/test_user_context.py b/tests/test_user_context.py index 4d601771..affe1062 100644 --- a/tests/test_user_context.py +++ b/tests/test_user_context.py @@ -1568,9 +1568,6 @@ def test_should_return_valid_decision_after_setting_invalid_delivery_rule_variat 'rule (211127) and user (test_user) in the forced decision map.' ]))) - # TODO - JAE: Can we change the test name and description? Not clear which part is invalid. - # Also, I see the forced set flag and decide flag is different. Is it intentional? - # TODO - CHECK WITH JAE if this test should return valid decision like docstring says! def test_should_return_valid_decision_after_setting_invalid_experiment_rule_variation_in_forced_decision(self): """ Should return valid decision after setting invalid experiment rule variation in forced decision. @@ -1596,18 +1593,6 @@ def test_should_return_valid_decision_after_setting_invalid_experiment_rule_vari self.assertEqual(decide_decision.user_context.user_id, 'test_user') self.assertEqual(decide_decision.user_context.get_user_attributes(), {}) - # expected_reasons = [ - # 'Evaluating audiences for rule 1: ["11154"].', 'Audiences for rule 1 collectively evaluated to FALSE.', - # 'User "test_user" does not meet audience conditions for targeting rule 1.', - # 'Evaluating audiences for rule 2: ["11159"].', 'Audiences for rule 2 collectively evaluated to FALSE.', - # 'User "test_user" does not meet audience conditions for targeting rule 2.', - # 'Evaluating audiences for rule Everyone Else: [].', - # 'Audiences for rule Everyone Else collectively evaluated to TRUE.', - # 'User "test_user" meets audience conditions for targeting rule Everyone Else.', - # 'User "test_user" bucketed into a targeting rule Everyone Else.' - # ] - - # TODO - BELOW ARE NEW UPDATED REASONS expected_reasons = [ 'Invalid variation is mapped to flag (test_feature_in_experiment), rule (test_experiment) ' 'and user (test_user) in the forced decision map.',