Skip to content

Commit ccea7b5

Browse files
Niloth-ptimabbott
authored andcommitted
test_model: Add varied test cases for testing reaction event handling.
1 parent 2125dc5 commit ccea7b5

File tree

1 file changed

+110
-15
lines changed

1 file changed

+110
-15
lines changed

tests/model/test_model.py

+110-15
Original file line numberDiff line numberDiff line change
@@ -2986,19 +2986,119 @@ def test__handle_reaction_event_not_in_index(
29862986
assert model.index == previous_index
29872987
assert not model._update_rendered_view.called
29882988

2989-
@pytest.mark.parametrize(
2990-
"op, expected_number_after",
2991-
[
2992-
("add", 2),
2993-
("remove", 1), # Removed emoji doesn't match, so length remains 1
2994-
],
2995-
)
29962989
@pytest.mark.parametrize(
29972990
"reaction_event_schema", ["with_user", "with_user_id", "with_both"]
29982991
)
29992992
@pytest.mark.parametrize(
30002993
"reaction_schema", ["with_user", "with_user_id", "with_both"]
30012994
)
2995+
@pytest.mark.parametrize(
2996+
"msgs, op, expected_number_after",
2997+
[
2998+
case(
2999+
[
3000+
(2, [(5140, "unicode_emoji", "2764", "heart")]),
3001+
(1, []),
3002+
],
3003+
"add",
3004+
2,
3005+
id="single_reaction_add",
3006+
),
3007+
case(
3008+
[
3009+
(2, [(5140, "unicode_emoji", "1f44d", "thumbs_up")]),
3010+
(1, []),
3011+
],
3012+
"remove",
3013+
0,
3014+
id="single_reaction_remove",
3015+
),
3016+
case(
3017+
[
3018+
(
3019+
2,
3020+
[
3021+
(3478, "unicode_emoji", "1f44d", "thumbs_up"),
3022+
(3479, "unicode_emoji", "1f44d", "thumbs_up"),
3023+
],
3024+
),
3025+
],
3026+
"add",
3027+
3,
3028+
id="same_emoji_different_users_add",
3029+
),
3030+
case(
3031+
[
3032+
(
3033+
2,
3034+
[
3035+
(3478, "unicode_emoji", "1f44d", "thumbs_up"),
3036+
(5140, "unicode_emoji", "1f44d", "thumbs_up"),
3037+
],
3038+
),
3039+
],
3040+
"remove",
3041+
1,
3042+
id="same_emoji_different_users_remove",
3043+
),
3044+
case(
3045+
[
3046+
(
3047+
2,
3048+
[
3049+
(5140, "zulip_extra_emoji", "zulip", "zulip"),
3050+
(3478, "unicode_emoji", "2764", "heart"),
3051+
],
3052+
),
3053+
],
3054+
"add",
3055+
3,
3056+
id="different_emoji_different_users_add",
3057+
),
3058+
case(
3059+
[
3060+
(
3061+
2,
3062+
[
3063+
(5140, "unicode_emoji", "1f44d", "thumbs_up"),
3064+
(3478, "unicode_emoji", "2764", "heart"),
3065+
],
3066+
),
3067+
],
3068+
"remove",
3069+
1,
3070+
id="different_emoji_different_users_remove",
3071+
),
3072+
case(
3073+
[
3074+
(
3075+
2,
3076+
[
3077+
(5140, "zulip_extra_emoji", "zulip", "zulip"),
3078+
(5140, "unicode_emoji", "2764", "heart"),
3079+
],
3080+
),
3081+
],
3082+
"add",
3083+
3,
3084+
id="different_emoji_same_user_add",
3085+
),
3086+
case(
3087+
[
3088+
(
3089+
2,
3090+
[
3091+
(5140, "unicode_emoji", "1f44d", "thumbs_up"),
3092+
(5140, "unicode_emoji", "5678", "heart"),
3093+
],
3094+
),
3095+
],
3096+
"remove",
3097+
1,
3098+
id="different_emoji_same_user_remove",
3099+
),
3100+
],
3101+
)
30023102
def test__handle_reaction_event_for_msg_in_index(
30033103
self,
30043104
mocker,
@@ -3008,8 +3108,9 @@ def test__handle_reaction_event_for_msg_in_index(
30083108
op,
30093109
reaction_event_schema,
30103110
reaction_schema,
3111+
msgs,
30113112
expected_number_after,
3012-
event_message_id=1,
3113+
event_message_id=2,
30133114
):
30143115
common_args = {
30153116
"op": op,
@@ -3024,13 +3125,7 @@ def test__handle_reaction_event_for_msg_in_index(
30243125
**common_args, user=True, user_id=5140
30253126
)
30263127

3027-
model.index = reaction_event_index_factory(
3028-
[
3029-
(1, [(1, "unicode_emoji", "1232", "thumbs_up")]),
3030-
(2, []),
3031-
],
3032-
reaction_schema,
3033-
)
3128+
model.index = reaction_event_index_factory(msgs, reaction_schema)
30343129
model._update_rendered_view = mocker.Mock()
30353130

30363131
model._handle_reaction_event(reaction_event)

0 commit comments

Comments
 (0)