diff --git a/tests/base.py b/tests/base.py index cb4d8c30..f2399fb4 100644 --- a/tests/base.py +++ b/tests/base.py @@ -381,263 +381,3 @@ def setUp(self): self.optimizely = optimizely.Optimizely(json.dumps(self.config_dict)) self.project_config = self.optimizely.config - - -class BaseTestV3(unittest.TestCase): - - def setUp(self): - self.config_dict = { - 'revision': '42', - 'version': '2', - 'events': [{ - 'key': 'test_event', - 'experimentIds': ['111127'], - 'id': '111095' - }, { - 'key': 'Total Revenue', - 'experimentIds': ['111127'], - 'id': '111096' - }], - 'experiments': [{ - 'key': 'test_experiment', - 'status': 'Running', - 'forcedVariations': { - 'user_1': 'control', - 'user_2': 'control' - }, - 'layerId': '111182', - 'audienceIds': ['11154'], - 'trafficAllocation': [{ - 'entityId': '111128', - 'endOfRange': 4000 - }, { - 'entityId': '', - 'endOfRange': 5000 - }, { - 'entityId': '111129', - 'endOfRange': 9000 - }], - 'id': '111127', - 'variations': [{ - 'key': 'control', - 'id': '111128' - }, { - 'key': 'variation', - 'id': '111129' - }] - }], - 'groups': [{ - 'id': '19228', - 'policy': 'random', - 'experiments': [{ - 'id': '32222', - 'key': 'group_exp_1', - 'status': 'Running', - 'audienceIds': [], - 'layerId': '111183', - 'variations': [{ - 'key': 'group_exp_1_control', - 'id': '28901' - }, { - 'key': 'group_exp_1_variation', - 'id': '28902' - }], - 'forcedVariations': { - 'user_1': 'group_exp_1_control', - 'user_2': 'group_exp_1_control' - }, - 'trafficAllocation': [{ - 'entityId': '28901', - 'endOfRange': 3000 - }, { - 'entityId': '28902', - 'endOfRange': 9000 - }] - }, { - 'id': '32223', - 'key': 'group_exp_2', - 'status': 'Running', - 'audienceIds': [], - 'layerId': '111184', - 'variations': [{ - 'key': 'group_exp_2_control', - 'id': '28905' - }, { - 'key': 'group_exp_2_variation', - 'id': '28906' - }], - 'forcedVariations': { - 'user_1': 'group_exp_2_control', - 'user_2': 'group_exp_2_control' - }, - 'trafficAllocation': [{ - 'entityId': '28905', - 'endOfRange': 8000 - }, { - 'entityId': '28906', - 'endOfRange': 10000 - }] - }], - 'trafficAllocation': [{ - 'entityId': '32222', - "endOfRange": 3000 - }, { - 'entityId': '32223', - 'endOfRange': 7500 - }] - }], - 'accountId': '12001', - 'attributes': [{ - 'key': 'test_attribute', - 'id': '111094' - }], - 'audiences': [{ - 'name': 'Test attribute users', - 'conditions': '["and", ["or", ["or", ' - '{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]', - 'id': '11154' - }, { - 'name': 'Test attribute users', - 'conditions': '["and", ["or", ["or", ' - '{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_2"}]]]', - 'id': '11159' - }], - 'projectId': '111001' - } - - # datafile version 4 - self.config_dict_with_features = { - 'revision': '1', - 'accountId': '12001', - 'projectId': '111111', - 'version': '4', - 'events': [{ - 'key': 'test_event', - 'experimentIds': ['111127'], - 'id': '111095' - }], - 'experiments': [{ - 'key': 'test_experiment', - 'status': 'Running', - 'forcedVariations': {}, - 'layerId': '111182', - 'audienceIds': [], - 'trafficAllocation': [{ - 'entityId': '111128', - 'endOfRange': 5000 - }, { - 'entityId': '111129', - 'endOfRange': 9000 - }], - 'id': '111127', - 'variations': [{ - 'key': 'control', - 'id': '111128', - 'variables': [{ - 'id': '127', 'value': 'false' - }, { - 'id': '128', 'value': 'prod' - }] - }, { - 'key': 'variation', - 'id': '111129' - }] - }], - 'groups': [], - 'attributes': [{ - 'key': 'test_attribute', - 'id': '111094' - }], - 'audiences': [{ - 'name': 'Test attribute users 1', - 'conditions': '["and", ["or", ["or", ' - '{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]', - 'id': '11154' - }, { - 'name': 'Test attribute users 2', - 'conditions': '["and", ["or", ["or", ' - '{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_2"}]]]', - 'id': '11159' - }], - 'rollouts': [{ - 'id': '201111', - 'experiments': [] - }, { - 'id': '211111', - 'experiments': [{ - 'id': '211127', - 'key': '211127', - 'status': 'Running', - 'forcedVariations': {}, - 'layerId': '211111', - 'audienceIds': ['11154'], - 'trafficAllocation': [{ - 'entityId': '211129', - 'endOfRange': 9000 - }], - 'variations': [{ - 'key': '211129', - 'id': '211129' - }] - }, { - 'id': '211137', - 'key': '211137', - 'status': 'Running', - 'forcedVariations': {}, - 'layerId': '211111', - 'audienceIds': ['11159'], - 'trafficAllocation': [{ - 'entityId': '211139', - 'endOfRange': 3000 - }], - 'variations': [{ - 'key': '211139', - 'id': '211139' - }] - }, { - 'id': '211147', - 'key': '211147', - 'status': 'Running', - 'forcedVariations': {}, - 'layerId': '211111', - 'audienceIds': [], - 'trafficAllocation': [{ - 'entityId': '211149', - 'endOfRange': 6000 - }], - 'variations': [{ - 'key': '211149', - 'id': '211149' - }] - }] - }], - 'featureFlags': [{ - 'id': '91111', - 'key': '91111', - 'experimentIds': ['111127'], - 'rolloutId': '', - 'variables': [{ - 'id': '127', - 'key': '127', - 'defaultValue': 'true', - 'type': 'boolean', - }, { - 'id': '128', - 'key': '128', - 'defaultValue': 'devel', - 'type': 'string', - }] - }, { - 'id': '91112', - 'key': '91112', - 'experimentIds': [], - 'rolloutId': '211111', - 'variables': [], - }] - } - - self.optimizely = optimizely.Optimizely(json.dumps(self.config_dict)) - self.config = project_config.ProjectConfig(json.dumps(self.config_dict), - logger.SimpleLogger(), error_handler.NoOpErrorHandler()) - self.optimizely.event_builder = event_builder.EventBuilderV3(self.config) - self.project_config = self.optimizely.config diff --git a/tests/test_config.py b/tests/test_config.py index db92dce8..5aa87efa 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -165,356 +165,6 @@ def test_init(self): self.assertEqual(expected_variation_key_map, self.project_config.variation_key_map) self.assertEqual(expected_variation_id_map, self.project_config.variation_id_map) - def test_init__with_v3_datafile(self): - """ Test that on creating object, properties are initiated correctly for version 3 datafile. """ - - # Adding some additional fields like live variables and IP anonymization - config_dict = { - 'revision': '42', - 'version': '3', - 'anonymizeIP': False, - 'variables': [{ - 'id': '127', - 'key': 'is_working', - 'defaultValue': 'true', - 'type': 'boolean', - }, { - 'id': '128', - 'key': 'environment', - 'defaultValue': 'devel', - 'type': 'string', - }, { - 'id': '129', - 'key': 'number_of_days', - 'defaultValue': '192', - 'type': 'integer', - }, { - 'id': '130', - 'key': 'significance_value', - 'defaultValue': '0.00098', - 'type': 'double', - }], - 'events': [{ - 'key': 'test_event', - 'experimentIds': ['111127'], - 'id': '111095' - }, { - 'key': 'Total Revenue', - 'experimentIds': ['111127'], - 'id': '111096' - }], - 'experiments': [{ - 'key': 'test_experiment', - 'status': 'Running', - 'forcedVariations': { - 'user_1': 'control', - 'user_2': 'control' - }, - 'layerId': '111182', - 'audienceIds': ['11154'], - 'trafficAllocation': [{ - 'entityId': '111128', - 'endOfRange': 4000 - }, { - 'entityId': '', - 'endOfRange': 5000 - }, { - 'entityId': '111129', - 'endOfRange': 9000 - }], - 'id': '111127', - 'variations': [{ - 'key': 'control', - 'id': '111128', - 'featureEnabled': False, - 'variables': [{ - 'id': '127', - 'value': 'false' - }] - }, { - 'key': 'variation', - 'id': '111129', - 'featureEnabled': False, - 'variables': [{ - 'id': '127', - 'value': 'true' - }] - }] - }], - 'groups': [{ - 'id': '19228', - 'policy': 'random', - 'experiments': [{ - 'id': '32222', - 'key': 'group_exp_1', - 'status': 'Running', - 'audienceIds': [], - 'layerId': '111183', - 'variations': [{ - 'key': 'group_exp_1_control', - 'id': '28901', - 'featureEnabled': False, - 'variables': [{ - 'id': '128', - 'value': 'prod' - }, { - 'id': '129', - 'value': '1772' - }, { - 'id': '130', - 'value': '1.22992' - }] - }, { - 'key': 'group_exp_1_variation', - 'id': '28902', - 'featureEnabled': False, - 'variables': [{ - 'id': '128', - 'value': 'stage' - }, { - 'id': '129', - 'value': '112' - }, { - 'id': '130', - 'value': '1.211' - }] - }], - 'forcedVariations': { - 'user_1': 'group_exp_1_control', - 'user_2': 'group_exp_1_control' - }, - 'trafficAllocation': [{ - 'entityId': '28901', - 'endOfRange': 3000 - }, { - 'entityId': '28902', - 'endOfRange': 9000 - }] - }, { - 'id': '32223', - 'key': 'group_exp_2', - 'status': 'Running', - 'audienceIds': [], - 'layerId': '111184', - 'variations': [{ - 'key': 'group_exp_2_control', - 'id': '28905', - 'featureEnabled': False, - 'variables': [] - }, { - 'key': 'group_exp_2_variation', - 'id': '28906', - 'featureEnabled': False, - 'variables': [] - }], - 'forcedVariations': { - 'user_1': 'group_exp_2_control', - 'user_2': 'group_exp_2_control' - }, - 'trafficAllocation': [{ - 'entityId': '28905', - 'endOfRange': 8000 - }, { - 'entityId': '28906', - 'endOfRange': 10000 - }] - }], - 'trafficAllocation': [{ - 'entityId': '32222', - 'endOfRange': 3000 - }, { - 'entityId': '32223', - 'endOfRange': 7500 - }] - }], - 'accountId': '12001', - 'attributes': [{ - 'key': 'test_attribute', - 'id': '111094' - }], - 'audiences': [{ - 'name': 'Test attribute users', - 'conditions': '["and", ["or", ["or", ' - '{"name": "test_attribute", "type": "custom_attribute", "value": "test_value"}]]]', - 'id': '11154' - }], - 'projectId': '111001' - } - - test_obj = optimizely.Optimizely(json.dumps(config_dict)) - project_config = test_obj.config - self.assertEqual(config_dict['accountId'], project_config.account_id) - self.assertEqual(config_dict['projectId'], project_config.project_id) - self.assertEqual(config_dict['revision'], project_config.revision) - self.assertEqual(config_dict['experiments'], project_config.experiments) - self.assertEqual(config_dict['events'], project_config.events) - - expected_group_id_map = { - '19228': entities.Group( - config_dict['groups'][0]['id'], - config_dict['groups'][0]['policy'], - config_dict['groups'][0]['experiments'], - config_dict['groups'][0]['trafficAllocation'] - ) - } - expected_experiment_key_map = { - 'test_experiment': entities.Experiment( - '111127', 'test_experiment', 'Running', ['11154'], [{ - 'key': 'control', - 'id': '111128', - 'featureEnabled': False, - 'variables': [{ - 'id': '127', - 'value': 'false' - }] - }, { - 'key': 'variation', - 'id': '111129', - 'featureEnabled': False, - 'variables': [{ - 'id': '127', - 'value': 'true' - }] - }], { - 'user_1': 'control', - 'user_2': 'control' - }, [{ - 'entityId': '111128', - 'endOfRange': 4000 - }, { - 'entityId': '', - 'endOfRange': 5000 - }, { - 'entityId': '111129', - 'endOfRange': 9000 - }], - '111182'), - 'group_exp_1': entities.Experiment( - '32222', 'group_exp_1', 'Running', [], [{ - 'key': 'group_exp_1_control', - 'id': '28901', - 'featureEnabled': False, - 'variables': [{ - 'id': '128', - 'value': 'prod' - }, { - 'id': '129', - 'value': '1772' - }, { - 'id': '130', - 'value': '1.22992' - }] - }, { - 'key': 'group_exp_1_variation', - 'id': '28902', - 'featureEnabled': False, - 'variables': [{ - 'id': '128', - 'value': 'stage' - }, { - 'id': '129', - 'value': '112' - }, { - 'id': '130', - 'value': '1.211' - }] - }], { - 'user_1': 'group_exp_1_control', - 'user_2': 'group_exp_1_control' - }, [{ - 'entityId': '28901', - 'endOfRange': 3000 - }, { - 'entityId': '28902', - 'endOfRange': 9000 - }], '111183', groupId='19228', groupPolicy='random' - ), - 'group_exp_2': entities.Experiment( - '32223', 'group_exp_2', 'Running', [], [{ - 'key': 'group_exp_2_control', - 'id': '28905', - 'featureEnabled': False, - 'variables': [] - }, { - 'key': 'group_exp_2_variation', - 'id': '28906', - 'featureEnabled': False, - 'variables': [] - }], { - 'user_1': 'group_exp_2_control', - 'user_2': 'group_exp_2_control' - }, [{ - 'entityId': '28905', - 'endOfRange': 8000 - }, { - 'entityId': '28906', - 'endOfRange': 10000 - }], '111184', groupId='19228', groupPolicy='random' - ), - } - expected_experiment_id_map = { - '111127': expected_experiment_key_map.get('test_experiment'), - '32222': expected_experiment_key_map.get('group_exp_1'), - '32223': expected_experiment_key_map.get('group_exp_2') - } - expected_event_key_map = { - 'test_event': entities.Event('111095', 'test_event', ['111127']), - 'Total Revenue': entities.Event('111096', 'Total Revenue', ['111127']) - } - expected_attribute_key_map = { - 'test_attribute': entities.Attribute('111094', 'test_attribute', segmentId='11133') - } - expected_audience_id_map = { - '11154': entities.Audience( - '11154', 'Test attribute users', - '["and", ["or", ["or", {"name": "test_attribute", "type": "custom_attribute", "value": "test_value"}]]]', - conditionStructure=['and', ['or', ['or', 0]]], - conditionList=[['test_attribute', 'test_value']] - ) - } - expected_variation_key_map = { - 'test_experiment': { - 'control': entities.Variation('111128', 'control', False, [{'id': '127', 'value': 'false'}]), - 'variation': entities.Variation('111129', 'variation', False, [{'id': '127', 'value': 'true'}]) - }, - 'group_exp_1': { - 'group_exp_1_control': entities.Variation( - '28901', 'group_exp_1_control', False, [ - {'id': '128', 'value': 'prod'}, {'id': '129', 'value': '1772'}, {'id': '130', 'value': '1.22992'}]), - 'group_exp_1_variation': entities.Variation( - '28902', 'group_exp_1_variation', False, [ - {'id': '128', 'value': 'stage'}, {'id': '129', 'value': '112'}, {'id': '130', 'value': '1.211'}]) - }, - 'group_exp_2': { - 'group_exp_2_control': entities.Variation('28905', 'group_exp_2_control'), - 'group_exp_2_variation': entities.Variation('28906', 'group_exp_2_variation') - } - } - expected_variation_id_map = { - 'test_experiment': { - '111128': entities.Variation('111128', 'control', False, [{'id': '127', 'value': 'false'}]), - '111129': entities.Variation('111129', 'variation', False, [{'id': '127', 'value': 'true'}]) - }, - 'group_exp_1': { - '28901': entities.Variation('28901', 'group_exp_1_control', False, [ - {'id': '128', 'value': 'prod'}, {'id': '129', 'value': '1772'}, {'id': '130', 'value': '1.22992'}]), - '28902': entities.Variation('28902', 'group_exp_1_variation', False, [ - {'id': '128', 'value': 'stage'}, {'id': '129', 'value': '112'}, {'id': '130', 'value': '1.211'}]) - }, - 'group_exp_2': { - '28905': entities.Variation('28905', 'group_exp_2_control'), - '28906': entities.Variation('28906', 'group_exp_2_variation') - } - } - self.assertEqual(expected_group_id_map, project_config.group_id_map) - self.assertEqual(expected_experiment_key_map, project_config.experiment_key_map) - self.assertEqual(expected_experiment_id_map, project_config.experiment_id_map) - self.assertEqual(expected_event_key_map, project_config.event_key_map) - self.assertEqual(expected_attribute_key_map, project_config.attribute_key_map) - self.assertEqual(expected_audience_id_map, project_config.audience_id_map) - self.assertEqual(expected_variation_key_map, project_config.variation_key_map) - self.assertEqual(expected_variation_id_map, project_config.variation_id_map) - def test_init__with_v4_datafile(self): """ Test that on creating object, properties are initiated correctly for version 4 datafile. """