@@ -2862,21 +2862,25 @@ def test__update_rendered_view_change_narrow(
2862
2862
2863
2863
@pytest .fixture
2864
2864
def reaction_event_factory (self ):
2865
- def _factory (* , op : str , message_id : int ):
2866
- return {
2867
- "emoji_code" : "1f44d" ,
2865
+ def _factory (* , op : str , message_id : int , user = None , user_id = None ):
2866
+ base_event = {
2868
2867
"id" : 2 ,
2869
- "user" : {
2870
-
2871
- "user_id" : 5140 ,
2872
- "full_name" : "Foo Boo" ,
2873
- },
2868
+ "emoji_code" : "1f44d" ,
2874
2869
"reaction_type" : "unicode_emoji" ,
2875
2870
"message_id" : message_id ,
2876
2871
"emoji_name" : "thumbs_up" ,
2877
2872
"type" : "reaction" ,
2878
2873
"op" : op ,
2879
2874
}
2875
+ if user is not None :
2876
+ base_event ["user" ] = {
2877
+
2878
+ "user_id" : 5140 ,
2879
+ "full_name" : "Foo Boo" ,
2880
+ }
2881
+ if user_id is not None :
2882
+ base_event ["user_id" ] = user_id
2883
+ return base_event
2880
2884
2881
2885
return _factory
2882
2886
@@ -2885,28 +2889,45 @@ def reaction_event_index_factory(self):
2885
2889
"""
2886
2890
Generate index for reaction tests based on minimal specification
2887
2891
2888
- Input is a list of pairs, of a message-id and a list of reaction tuples
2892
+ Input:
2893
+ - msgs: A list of tuples where each tuple contains:
2894
+ - A message ID
2895
+ - A list of reaction tuples, where each reaction includes:
2896
+ - user_id
2897
+ - reaction_type
2898
+ - emoji_code
2899
+ - emoji_name
2900
+ - schema: Defines the fields present in the reaction
2901
+ (e.g., "with_user", "with_user_id", "with_both")
2902
+
2889
2903
NOTE: reactions as None indicate not indexed, [] indicates no reaction
2890
2904
"""
2891
2905
MsgsType = List [Tuple [int , Optional [List [Tuple [int , str , str , str ]]]]]
2892
2906
2893
- def _factory (msgs : MsgsType ):
2907
+ def _factory (msgs : MsgsType , schema = "with_user" ):
2908
+ def build_reaction (user_id , type , code , name ):
2909
+ reaction = {
2910
+ "reaction_type" : type ,
2911
+ "emoji_code" : code ,
2912
+ "emoji_name" : name ,
2913
+ }
2914
+ if schema in {"with_user" , "with_both" }:
2915
+ reaction ["user" ] = {
2916
+ "email" : f"User email #{ user_id } " ,
2917
+ "full_name" : f"User #{ user_id } " ,
2918
+ "id" : user_id ,
2919
+ }
2920
+ if schema in {"with_user_id" , "with_both" }:
2921
+ reaction ["user_id" ] = user_id
2922
+ return reaction
2923
+
2894
2924
return {
2895
2925
"messages" : {
2896
2926
message_id : {
2897
2927
"id" : message_id ,
2898
2928
"content" : f"message content { message_id } " ,
2899
2929
"reactions" : [
2900
- {
2901
- "user" : {
2902
- "email" : f"User email #{ user_id } " ,
2903
- "full_name" : f"User #{ user_id } " ,
2904
- "id" : user_id ,
2905
- },
2906
- "reaction_type" : type ,
2907
- "emoji_code" : code ,
2908
- "emoji_name" : name ,
2909
- }
2930
+ build_reaction (user_id , type , code , name )
2910
2931
for user_id , type , code , name in reactions
2911
2932
],
2912
2933
}
@@ -2918,25 +2939,43 @@ def _factory(msgs: MsgsType):
2918
2939
return _factory
2919
2940
2920
2941
@pytest .mark .parametrize ("op" , ["add" , "remove" ])
2942
+ @pytest .mark .parametrize (
2943
+ "reaction_event_schema" , ["with_user" , "with_user_id" , "with_both" ]
2944
+ )
2945
+ @pytest .mark .parametrize (
2946
+ "reaction_schema" , ["with_user" , "with_user_id" , "with_both" ]
2947
+ )
2921
2948
def test__handle_reaction_event_not_in_index (
2922
2949
self ,
2923
2950
mocker ,
2924
2951
model ,
2925
2952
reaction_event_factory ,
2926
2953
reaction_event_index_factory ,
2927
2954
op ,
2955
+ reaction_event_schema ,
2956
+ reaction_schema ,
2928
2957
unindexed_message_id = 1 ,
2929
2958
):
2930
- reaction_event = reaction_event_factory (
2931
- op = op ,
2932
- message_id = unindexed_message_id ,
2933
- )
2959
+ common_args = {
2960
+ "op" : op ,
2961
+ "message_id" : unindexed_message_id ,
2962
+ }
2963
+ if reaction_event_schema == "with_user" :
2964
+ reaction_event = reaction_event_factory (** common_args , user = True )
2965
+ elif reaction_event_schema == "with_user_id" :
2966
+ reaction_event = reaction_event_factory (** common_args , user_id = 5140 )
2967
+ else :
2968
+ reaction_event = reaction_event_factory (
2969
+ ** common_args , user = True , user_id = 5140
2970
+ )
2971
+
2934
2972
model .index = reaction_event_index_factory (
2935
2973
[
2936
2974
(unindexed_message_id , None ), # explicitly exclude
2937
2975
(2 , [(1 , "unicode_emoji" , "1232" , "thumbs_up" )]),
2938
2976
(3 , []),
2939
- ]
2977
+ ],
2978
+ reaction_schema ,
2940
2979
)
2941
2980
model ._update_rendered_view = mocker .Mock ()
2942
2981
previous_index = deepcopy (model .index )
@@ -2954,25 +2993,43 @@ def test__handle_reaction_event_not_in_index(
2954
2993
("remove" , 1 ), # Removed emoji doesn't match, so length remains 1
2955
2994
],
2956
2995
)
2996
+ @pytest .mark .parametrize (
2997
+ "reaction_event_schema" , ["with_user" , "with_user_id" , "with_both" ]
2998
+ )
2999
+ @pytest .mark .parametrize (
3000
+ "reaction_schema" , ["with_user" , "with_user_id" , "with_both" ]
3001
+ )
2957
3002
def test__handle_reaction_event_for_msg_in_index (
2958
3003
self ,
2959
3004
mocker ,
2960
3005
model ,
2961
3006
reaction_event_factory ,
2962
3007
reaction_event_index_factory ,
2963
3008
op ,
3009
+ reaction_event_schema ,
3010
+ reaction_schema ,
2964
3011
expected_number_after ,
2965
3012
event_message_id = 1 ,
2966
3013
):
2967
- reaction_event = reaction_event_factory (
2968
- op = op ,
2969
- message_id = event_message_id ,
2970
- )
3014
+ common_args = {
3015
+ "op" : op ,
3016
+ "message_id" : event_message_id ,
3017
+ }
3018
+ if reaction_event_schema == "with_user" :
3019
+ reaction_event = reaction_event_factory (** common_args , user = True )
3020
+ elif reaction_event_schema == "with_user_id" :
3021
+ reaction_event = reaction_event_factory (** common_args , user_id = 5140 )
3022
+ else :
3023
+ reaction_event = reaction_event_factory (
3024
+ ** common_args , user = True , user_id = 5140
3025
+ )
3026
+
2971
3027
model .index = reaction_event_index_factory (
2972
3028
[
2973
3029
(1 , [(1 , "unicode_emoji" , "1232" , "thumbs_up" )]),
2974
3030
(2 , []),
2975
- ]
3031
+ ],
3032
+ reaction_schema ,
2976
3033
)
2977
3034
model ._update_rendered_view = mocker .Mock ()
2978
3035
0 commit comments