Skip to content

Commit 22c42ca

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 6c61e2a commit 22c42ca

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ def initial_unread_counts():
757757
def index_multiple_messages():
758758
"""
759759
Index fixture filled with multiple entries for messages.
760+
Private messages have minimal data required to test `set_count`.
761+
More can be added if and when required.
760762
"""
761763
return dict(helper_initial_index, **{'messages': {
762764
1: {'id': 1, 'type': 'stream', 'subject': 'Topic 1',
@@ -777,4 +779,19 @@ def index_multiple_messages():
777779
'sender_id': 101, 'stream_id': 1003, 'display_recipient': []},
778780
9: {'id': 9, 'type': 'stream', 'subject': 'Topic 100',
779781
'sender_id': 101, 'stream_id': 1003, 'display_recipient': []},
782+
# pms
783+
10: {'id': 10, 'type': 'private', 'subject': 'hello', 'sender_id': 200,
784+
'display_recipient': [{'id': 202}, {'id': 200}]},
785+
11: {'id': 11, 'type': 'private', 'subject': 'hi', 'sender_id': 201,
786+
'display_recipient': [{'id': 202}, {'id': 201}]},
787+
12: {'id': 12, 'type': 'private', 'subject': 'hola', 'sender_id': 202,
788+
'display_recipient': [{'id': 202}, {'id': 201}]},
789+
13: {'id': 13, 'type': 'private', 'subject': 'hello', 'sender_id': 200,
790+
'display_recipient': [{'id': 202}, {'id': 200}]},
791+
14: {'id': 14, 'type': 'private', 'subject': 'hi', 'sender_id': 201,
792+
'display_recipient': [{'id': 202}, {'id': 201}]},
793+
15: {'id': 15, 'type': 'private', 'subject': 'self', 'sender_id': 202,
794+
'display_recipient': [{'id': 202}]},
795+
16: {'id': 16, 'type': 'private', 'subject': 'hello', 'sender_id': 200,
796+
'display_recipient': [{'id': 202}, {'id': 200}]},
780797
}})

tests/helper/test_helper.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,39 @@ 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+
# (1, [15], 4, 3, {200: 2, 201: 1}), # self-pm # FIXME
62+
])
63+
def test_set_count_pms(mocker, initial_unread_counts, all_msg,
64+
all_pms, unread_pms, user_id, id_list, new_count,
65+
expected_unread_pms, expected_all_pms,
66+
expected_all_msg, index_multiple_messages):
67+
controller = mocker.patch('zulipterminal.core.Controller.__init__')
68+
controller.model.index = index_multiple_messages
69+
controller.model.user_id = user_id
70+
71+
unread_counts = deepcopy(dict(initial_unread_counts,
72+
**{'all_msg': all_msg, 'all_pms': all_pms,
73+
'unread_pms': unread_pms}))
74+
expected_unread_counts = dict(initial_unread_counts,
75+
**{'all_msg': expected_all_msg,
76+
'all_pms': expected_all_pms,
77+
'unread_pms': expected_unread_pms})
78+
controller.model.unread_counts = unread_counts
79+
set_count(id_list, controller, new_count)
80+
assert controller.model.unread_counts == expected_unread_counts
81+
82+
5083
def test_index_messages_narrow_all_messages(mocker,
5184
messages_successful_response,
5285
index_all_messages,

0 commit comments

Comments
 (0)