@@ -4890,6 +4890,66 @@ def test_odp_events_not_sent_with_legacy_apis(self):
4890
4890
4891
4891
client .close ()
4892
4892
4893
+ def test_activate_with_cmab_uuid (self ):
4894
+ """ Test that activate includes CMAB UUID when available from CMAB service. """
4895
+ expected_cmab_uuid = "test-cmab-uuid-123"
4896
+ variation_result = {
4897
+ 'variation' : self .project_config .get_variation_from_id ('test_experiment' , '111129' ),
4898
+ 'cmab_uuid' : expected_cmab_uuid ,
4899
+ 'reasons' : [],
4900
+ 'error' : False
4901
+ }
4902
+
4903
+ with mock .patch (
4904
+ 'optimizely.decision_service.DecisionService.get_variation' ,
4905
+ return_value = variation_result ,
4906
+ ), mock .patch ('time.time' , return_value = 42 ), mock .patch (
4907
+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
4908
+ ), mock .patch (
4909
+ 'optimizely.event.event_processor.BatchEventProcessor.process'
4910
+ ) as mock_process :
4911
+ result = self .optimizely .activate ('test_experiment' , 'test_user' )
4912
+ self .assertEqual ('variation' , result )
4913
+
4914
+ # Verify the impression event includes CMAB UUID
4915
+ impression_event = mock_process .call_args [0 ][0 ]
4916
+ self .assertEqual (impression_event .cmab_uuid , expected_cmab_uuid )
4917
+
4918
+ # Verify the log event includes CMAB UUID in metadata
4919
+ log_event = EventFactory .create_log_event (impression_event , self .optimizely .logger )
4920
+ metadata = log_event .params ['visitors' ][0 ]['snapshots' ][0 ]['decisions' ][0 ]['metadata' ]
4921
+ self .assertIn ('cmab_uuid' , metadata )
4922
+ self .assertEqual (metadata ['cmab_uuid' ], expected_cmab_uuid )
4923
+
4924
+ def test_activate_without_cmab_uuid (self ):
4925
+ """ Test that activate works correctly when CMAB service returns None. """
4926
+ variation_result = {
4927
+ 'variation' : self .project_config .get_variation_from_id ('test_experiment' , '111129' ),
4928
+ 'cmab_uuid' : None ,
4929
+ 'reasons' : [],
4930
+ 'error' : False
4931
+ }
4932
+
4933
+ with mock .patch (
4934
+ 'optimizely.decision_service.DecisionService.get_variation' ,
4935
+ return_value = variation_result ,
4936
+ ), mock .patch ('time.time' , return_value = 42 ), mock .patch (
4937
+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
4938
+ ), mock .patch (
4939
+ 'optimizely.event.event_processor.BatchEventProcessor.process'
4940
+ ) as mock_process :
4941
+ result = self .optimizely .activate ('test_experiment' , 'test_user' )
4942
+ self .assertEqual ('variation' , result )
4943
+
4944
+ # Verify the impression event has no CMAB UUID
4945
+ impression_event = mock_process .call_args [0 ][0 ]
4946
+ self .assertIsNone (impression_event .cmab_uuid )
4947
+
4948
+ # Verify the log event does not include CMAB UUID in metadata
4949
+ log_event = EventFactory .create_log_event (impression_event , self .optimizely .logger )
4950
+ metadata = log_event .params ['visitors' ][0 ]['snapshots' ][0 ]['decisions' ][0 ]['metadata' ]
4951
+ self .assertNotIn ('cmab_uuid' , metadata )
4952
+
4893
4953
4894
4954
class OptimizelyWithExceptionTest (base .BaseTest ):
4895
4955
def setUp (self ):
0 commit comments