Skip to content

Commit 3d7c946

Browse files
committed
tests: helper: Test set_count for private messages.
Add test for verifying unread_counts when marking pms as read/unread. Add pm message entries to index fixture.
1 parent 7bd53f7 commit 3d7c946

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ def initial_unread_counts():
771771
def index_multiple_messages():
772772
"""
773773
Index fixture filled with multiple entries for messages.
774+
Private messages have minimal data required to test `set_count`.
775+
More can be added if and when required.
774776
"""
775777
return dict(helper_initial_index, **{'messages': {
776778
1: {'id': 1, 'type': 'stream', 'subject': 'Topic 1', 'sender_id': 99,
@@ -791,6 +793,21 @@ def index_multiple_messages():
791793
'stream_id': 1003, 'display_recipient': 'stream 10'},
792794
9: {'id': 9, 'type': 'stream', 'subject': 'Topic 10', 'sender_id': 101,
793795
'stream_id': 1003, 'display_recipient': 'stream 10'},
796+
# pms
797+
10: {'id': 10, 'type': 'private', 'sender_id': 200,
798+
'display_recipient': [{'id': 202}, {'id': 200}]},
799+
11: {'id': 11, 'type': 'private', 'sender_id': 201,
800+
'display_recipient': [{'id': 202}, {'id': 201}]},
801+
12: {'id': 12, 'type': 'private', 'sender_id': 202,
802+
'display_recipient': [{'id': 202}, {'id': 201}]},
803+
13: {'id': 13, 'type': 'private', 'sender_id': 200,
804+
'display_recipient': [{'id': 202}, {'id': 200}]},
805+
14: {'id': 14, 'type': 'private', 'sender_id': 201,
806+
'display_recipient': [{'id': 202}, {'id': 201}]},
807+
15: {'id': 15, 'type': 'private', 'sender_id': 202,
808+
'display_recipient': [{'id': 202}]},
809+
16: {'id': 16, 'type': 'private', 'sender_id': 200,
810+
'display_recipient': [{'id': 202}, {'id': 200}]},
794811
}})
795812
# --------------- UI Fixtures -----------------------------------------
796813

tests/helper/test_helper.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ def test_set_count_stream(mocker, initial_unread_counts,
4747
assert controller.model.unread_counts == expected_unread_counts
4848

4949

50+
@pytest.mark.parametrize('all_msg, all_pms, unread_pms, user_id', [
51+
(4, 3, {200: 2, 201: 1}, 202)
52+
])
53+
@pytest.mark.parametrize(('new_count, id_list, expected_all_msg,'
54+
'expected_all_pms, expected_unread_pms'), [
55+
(-1, [10, 13], 2, 1, {201: 1}),
56+
(-1, [10, 13, 11], 1, 0, {}),
57+
(-1, [], 4, 3, {200: 2, 201: 1}),
58+
(-1, [15], 4, 3, {200: 2, 201: 1}), # self-pm
59+
(1, [16, 10], 6, 5, {200: 4, 201: 1}),
60+
(1, [], 4, 3, {200: 2, 201: 1}),
61+
])
62+
def test_set_count_pms(mocker, initial_unread_counts, all_msg,
63+
all_pms, unread_pms, user_id, id_list, new_count,
64+
expected_unread_pms, expected_all_pms,
65+
expected_all_msg, index_multiple_messages):
66+
controller = mocker.patch('zulipterminal.core.Controller.__init__')
67+
controller.model.index = index_multiple_messages
68+
controller.model.user_id = user_id
69+
70+
unread_counts = deepcopy(dict(initial_unread_counts,
71+
**{'all_msg': all_msg, 'all_pms': all_pms,
72+
'unread_pms': unread_pms}))
73+
expected_unread_counts = dict(initial_unread_counts,
74+
**{'all_msg': expected_all_msg,
75+
'all_pms': expected_all_pms,
76+
'unread_pms': expected_unread_pms})
77+
controller.model.unread_counts = unread_counts
78+
set_count(id_list, controller, new_count)
79+
assert controller.model.unread_counts == expected_unread_counts
80+
81+
5082
def test_index_messages_narrow_all_messages(mocker,
5183
messages_successful_response,
5284
index_all_messages,

0 commit comments

Comments
 (0)