24
24
25
25
USER_ID = "t2_1234"
26
26
IS_LOGGED_IN = True
27
- AUTH_CLIENT_ID = "token"
28
- COUNTRY_CODE = "US"
29
- DEVICE_ID = "abc"
30
- COOKIE_CREATED_TIMESTAMP = 1234
31
- LOID_CREATED_TIMESTAMP = 123456
32
- LOCALE_CODE = "us_en"
33
- ORIGIN_SERVICE = "origin"
27
+ AD_ACCOUNT_ID = "t2_4321"
34
28
APP_NAME = "ios"
35
29
APP_VERSION = "0.0.0.0"
30
+ AUTH_CLIENT_ID = "token"
36
31
BUILD_NUMBER = 1
32
+ BUSINESS_ID = "t_some"
37
33
CANONICAL_URL = "www.test.com"
34
+ COOKIE_CREATED_TIMESTAMP = 1234
35
+ COUNTRY_CODE = "US"
36
+ DEVICE_ID = "abc"
38
37
EVENT_FIELDS = {
39
38
"user_id" : USER_ID ,
40
39
"logged_in" : IS_LOGGED_IN ,
41
40
"cookie_created_timestamp" : COOKIE_CREATED_TIMESTAMP ,
42
41
}
42
+ LOID_CREATED_TIMESTAMP = 123456
43
+ LOCALE_CODE = "us_en"
44
+ ORIGIN_SERVICE = "origin"
45
+ SUBREDDIT_ID = "t5_123abc"
43
46
44
47
45
48
@contextlib .contextmanager
@@ -706,6 +709,90 @@ def test_get_variant_for_identifier_device_id(self):
706
709
# `identifier` passed to correct event field of experiment's `bucket_val` config
707
710
self .assertEqual (event_fields ["device_id" ], identifier )
708
711
712
+ def test_get_variant_for_identifier_subreddit_id (self ):
713
+ identifier = SUBREDDIT_ID
714
+ bucket_val = "subreddit_id"
715
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
716
+
717
+ with create_temp_config_file (self .exp_base_config ) as f :
718
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
719
+
720
+ self .assertEqual (self .event_logger .log .call_count , 0 )
721
+ variant = decider .get_variant_for_identifier (
722
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
723
+ )
724
+ self .assertEqual (variant , "control_1" )
725
+
726
+ # exposure assertions
727
+ self .assertEqual (self .event_logger .log .call_count , 1 )
728
+ event_fields = self .event_logger .log .call_args [1 ]
729
+ self .assert_minimal_exposure_event_fields (
730
+ experiment_name = "exp_1" ,
731
+ variant = variant ,
732
+ event_fields = event_fields ,
733
+ bucket_val = bucket_val ,
734
+ identifier = identifier ,
735
+ )
736
+
737
+ # `identifier` passed to correct event field of experiment's `bucket_val` config
738
+ self .assertEqual (event_fields ["subreddit_id" ], identifier )
739
+
740
+ def test_get_variant_for_identifier_ad_account_id (self ):
741
+ identifier = AD_ACCOUNT_ID
742
+ bucket_val = "ad_account_id"
743
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
744
+
745
+ with create_temp_config_file (self .exp_base_config ) as f :
746
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
747
+
748
+ self .assertEqual (self .event_logger .log .call_count , 0 )
749
+ variant = decider .get_variant_for_identifier (
750
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
751
+ )
752
+ self .assertEqual (variant , "variant_2" )
753
+
754
+ # exposure assertions
755
+ self .assertEqual (self .event_logger .log .call_count , 1 )
756
+ event_fields = self .event_logger .log .call_args [1 ]
757
+ self .assert_minimal_exposure_event_fields (
758
+ experiment_name = "exp_1" ,
759
+ variant = variant ,
760
+ event_fields = event_fields ,
761
+ bucket_val = bucket_val ,
762
+ identifier = identifier ,
763
+ )
764
+
765
+ # `identifier` passed to correct event field of experiment's `bucket_val` config
766
+ self .assertEqual (event_fields ["ad_account_id" ], identifier )
767
+
768
+ def test_get_variant_for_identifier_business_id (self ):
769
+ identifier = BUSINESS_ID
770
+ bucket_val = "business_id"
771
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
772
+
773
+ with create_temp_config_file (self .exp_base_config ) as f :
774
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
775
+
776
+ self .assertEqual (self .event_logger .log .call_count , 0 )
777
+ variant = decider .get_variant_for_identifier (
778
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
779
+ )
780
+ self .assertEqual (variant , "control_2" )
781
+
782
+ # exposure assertions
783
+ self .assertEqual (self .event_logger .log .call_count , 1 )
784
+ event_fields = self .event_logger .log .call_args [1 ]
785
+ self .assert_minimal_exposure_event_fields (
786
+ experiment_name = "exp_1" ,
787
+ variant = variant ,
788
+ event_fields = event_fields ,
789
+ bucket_val = bucket_val ,
790
+ identifier = identifier ,
791
+ )
792
+
793
+ # `identifier` passed to correct event field of experiment's `bucket_val` config
794
+ self .assertEqual (event_fields ["business_id" ], identifier )
795
+
709
796
def test_get_variant_for_identifier_bogus_identifier_type (self ):
710
797
identifier = "anything"
711
798
identifier_type = "blah"
@@ -724,7 +811,7 @@ def test_get_variant_for_identifier_bogus_identifier_type(self):
724
811
self .assertEqual (variant , None )
725
812
726
813
assert any (
727
- "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url']."
814
+ "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url', 'subreddit_id', 'ad_account_id', 'business_id' ]."
728
815
in x .getMessage ()
729
816
for x in captured .records
730
817
)
@@ -847,6 +934,57 @@ def test_get_variant_for_identifier_without_expose_device_id(self):
847
934
# no exposures should be triggered
848
935
self .assertEqual (self .event_logger .log .call_count , 0 )
849
936
937
+ def test_get_variant_for_identifier_without_expose_subreddit_id (self ):
938
+ identifier = SUBREDDIT_ID
939
+ bucket_val = "subreddit_id"
940
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
941
+
942
+ with create_temp_config_file (self .exp_base_config ) as f :
943
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
944
+
945
+ self .assertEqual (self .event_logger .log .call_count , 0 )
946
+ variant = decider .get_variant_for_identifier_without_expose (
947
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
948
+ )
949
+ self .assertEqual (variant , "control_1" )
950
+
951
+ # no exposures should be triggered
952
+ self .assertEqual (self .event_logger .log .call_count , 0 )
953
+
954
+ def test_get_variant_for_identifier_without_expose_ad_account_id (self ):
955
+ identifier = AD_ACCOUNT_ID
956
+ bucket_val = "ad_account_id"
957
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
958
+
959
+ with create_temp_config_file (self .exp_base_config ) as f :
960
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
961
+
962
+ self .assertEqual (self .event_logger .log .call_count , 0 )
963
+ variant = decider .get_variant_for_identifier_without_expose (
964
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
965
+ )
966
+ self .assertEqual (variant , "variant_2" )
967
+
968
+ # no exposures should be triggered
969
+ self .assertEqual (self .event_logger .log .call_count , 0 )
970
+
971
+ def test_get_variant_for_identifier_without_expose_business_id (self ):
972
+ identifier = BUSINESS_ID
973
+ bucket_val = "business_id"
974
+ self .exp_base_config ["exp_1" ]["experiment" ].update ({"bucket_val" : bucket_val })
975
+
976
+ with create_temp_config_file (self .exp_base_config ) as f :
977
+ decider = setup_decider (f , self .dc , self .mock_span , self .event_logger )
978
+
979
+ self .assertEqual (self .event_logger .log .call_count , 0 )
980
+ variant = decider .get_variant_for_identifier_without_expose (
981
+ experiment_name = "exp_1" , identifier = identifier , identifier_type = bucket_val
982
+ )
983
+ self .assertEqual (variant , "control_2" )
984
+
985
+ # no exposures should be triggered
986
+ self .assertEqual (self .event_logger .log .call_count , 0 )
987
+
850
988
def test_get_variant_for_identifier_without_expose_bogus_identifier_type (self ):
851
989
identifier = "anything"
852
990
identifier_type = "blah"
@@ -863,7 +1001,7 @@ def test_get_variant_for_identifier_without_expose_bogus_identifier_type(self):
863
1001
self .assertEqual (variant , None )
864
1002
865
1003
assert any (
866
- "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url']."
1004
+ "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url', 'subreddit_id', 'ad_account_id', 'business_id' ]."
867
1005
in x .getMessage ()
868
1006
for x in captured .records
869
1007
)
@@ -1277,7 +1415,7 @@ def test_get_all_variants_for_identifier_without_expose_bogus_identifier_type(se
1277
1415
self .assertEqual (len (variant_arr ), 0 )
1278
1416
1279
1417
assert any (
1280
- "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url']."
1418
+ "\" blah\" is not one of supported \" identifier_type\" : ['user_id', 'device_id', 'canonical_url', 'subreddit_id', 'ad_account_id', 'business_id' ]."
1281
1419
in x .getMessage ()
1282
1420
for x in captured .records
1283
1421
)
0 commit comments