Skip to content

Commit 25f6758

Browse files
committed
conftest/model: Fetch server version and feature level via /register.
This adds zulip_version among the requested event_types to fetch zulip_version and zulip_feature_level via POST /register API endpoint. Feature level, a monotonic integer (starts from 1), is introduced in Zulip 2.2 and is always returned in POST /register from Feature Level 3 along with zulip_version. However, it is likely that some servers might choose to not adhere to feature level (the adapting code is present in model's init method). For testing, this also introduces zuilp_version fixture to test different components based on the server version and the feature level. Note: zulip_version fixture is not used, i.e. the server version and the feature level (using MINIMUM_SUPPORTED_SERVER_VERSION) are hard-coded, in initial_data fixture on purpose to avoid adding extra tests unnecessarily. Test amended. Fixes #616 partially.
1 parent d0f292b commit 25f6758

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from zulipterminal.helper import initial_index as helper_initial_index
99
from zulipterminal.ui_tools.boxes import MessageBox
1010
from zulipterminal.ui_tools.buttons import StreamButton, UserButton
11+
from zulipterminal.version import (
12+
MINIMUM_SUPPORTED_SERVER_VERSION, SUPPORTED_SERVER_VERSIONS,
13+
)
1114

1215

1316
@pytest.fixture(autouse=True)
@@ -312,6 +315,19 @@ def messages_successful_response() -> Dict[str, Any]:
312315
})
313316

314317

318+
@pytest.fixture(
319+
params=SUPPORTED_SERVER_VERSIONS,
320+
ids=(lambda param:
321+
'server_version:{}-server_feature_level:{}'.format(*param))
322+
)
323+
def zulip_version(request):
324+
"""
325+
Fixture to test different components based on the server version and the
326+
feature level.
327+
"""
328+
return request.param
329+
330+
315331
@pytest.fixture
316332
def initial_data(logged_on_user, users_fixture, streams_fixture):
317333
"""
@@ -467,6 +483,10 @@ def initial_data(logged_on_user, users_fixture, streams_fixture):
467483
'last_event_id': -1,
468484
'muted_topics': [],
469485
'realm_user_groups': [],
486+
# Deliberately use hard-coded zulip version and feature level to avoid
487+
# adding extra tests unnecessarily.
488+
'zulip_version': MINIMUM_SUPPORTED_SERVER_VERSION[0],
489+
'zulip_feature_level': MINIMUM_SUPPORTED_SERVER_VERSION[1],
470490
}
471491

472492

tests/model/test_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def test_init(self, model, initial_data, user_profile):
5353
num_after=10,
5454
anchor=None)
5555
assert model.initial_data == initial_data
56+
assert model.server_version == initial_data['zulip_version']
57+
assert model.server_feature_level == (
58+
initial_data.get('zulip_feature_level')
59+
)
5660
assert model.user_id == user_profile['user_id']
5761
assert model.user_full_name == user_profile['full_name']
5862
assert model.user_email == user_profile['email']
@@ -136,6 +140,7 @@ def test_register_initial_desired_events(self, mocker, initial_data):
136140
'muted_topics',
137141
'realm_user',
138142
'realm_user_groups',
143+
'zulip_version',
139144
]
140145
model.client.register.assert_called_once_with(
141146
event_types=event_types,

zulipterminal/model.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def __init__(self, controller: Any) -> None:
9898
# lose any updates while messages are being fetched.
9999
self._update_initial_data()
100100

101+
self.server_version = self.initial_data['zulip_version']
102+
self.server_feature_level = (
103+
self.initial_data.get('zulip_feature_level')
104+
)
105+
101106
self.users = self.get_all_users()
102107

103108
subscriptions = self.initial_data['subscriptions']
@@ -936,7 +941,10 @@ def _register_desired_events(self, *, fetch_data: bool=False) -> str:
936941
'update_message_flags',
937942
'muted_topics',
938943
'realm_user', # Enables cross_realm_bots
939-
'realm_user_groups'
944+
'realm_user_groups',
945+
# zulip_version and zulip_feature_level are always returned in
946+
# POST /register from Feature level 3.
947+
'zulip_version',
940948
]
941949
event_types = list(self.event_actions)
942950
try:

0 commit comments

Comments
 (0)