Skip to content

Commit 8cd406b

Browse files
committed
refactor: model/boxes: Store emoji data in model.
Save the data from emoji_data.py as a model attribute, instead of loading them directly from the file. This will make it easy, in the future, to use emoji data when it is fetched from different sources, for example - custom emojis that will be fetched using a server endpoint. Tests amended.
1 parent 8ffcd43 commit 8cd406b

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

tests/model/test_model.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def mock_external_classes(self, mocker: Any) -> None:
2424
'zulipterminal.model.display_error_if_present')
2525

2626
@pytest.fixture
27-
def model(self, mocker, initial_data, user_profile):
27+
def model(self, mocker, initial_data, user_profile,
28+
unicode_emojis):
2829
mocker.patch('zulipterminal.model.Model.get_messages',
2930
return_value='')
3031
self.client.register.return_value = initial_data
@@ -38,10 +39,13 @@ def model(self, mocker, initial_data, user_profile):
3839
'zulipterminal.model.classify_unread_counts',
3940
return_value=[])
4041
self.client.get_profile.return_value = user_profile
42+
mocker.patch('zulipterminal.model.emoji_data',
43+
EMOJI_DATA=unicode_emojis)
4144
model = Model(self.controller)
4245
return model
4346

44-
def test_init(self, model, initial_data, user_profile):
47+
def test_init(self, model, initial_data, user_profile,
48+
unicode_emojis):
4549
assert hasattr(model, 'controller')
4650
assert hasattr(model, 'client')
4751
assert model.narrow == []
@@ -71,6 +75,7 @@ def test_init(self, model, initial_data, user_profile):
7175
assert model.unpinned_streams == []
7276
self.classify_unread_counts.assert_called_once_with(model)
7377
assert model.unread_counts == []
78+
assert model.emoji_data == unicode_emojis
7479

7580
def test_init_InvalidAPIKey_response(self, mocker, initial_data):
7681
# Both network calls indicate the same response

tests/ui_tools/test_boxes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def mock_external_classes(self, mocker, initial_index):
1616
@pytest.fixture()
1717
def write_box(self, mocker, users_fixture, user_groups_fixture,
1818
streams_fixture, unicode_emojis):
19+
self.view.model.emoji_data = unicode_emojis
20+
1921
write_box = WriteBox(self.view)
2022
write_box.view.users = users_fixture
2123
write_box.model.user_group_names = [
@@ -26,8 +28,6 @@ def write_box(self, mocker, users_fixture, user_groups_fixture,
2628
[stream['name']] for stream in
2729
streams_fixture], key=lambda stream: stream[0].lower())
2830

29-
mocker.patch('zulipterminal.ui_tools.boxes.emoji_data',
30-
EMOJI_DATA=unicode_emojis)
3131
return write_box
3232

3333
def test_init(self, write_box):

zulipterminal/model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import zulip
1212
from mypy_extensions import TypedDict
1313

14+
from zulipterminal import emoji_data
1415
from zulipterminal.config.keys import keys_for_command
1516
from zulipterminal.helper import (
1617
Message, asynch, canonicalize_color, classify_unread_counts,
@@ -125,6 +126,8 @@ def __init__(self, controller: Any) -> None:
125126

126127
self.unread_counts = classify_unread_counts(self)
127128

129+
self.emoji_data = emoji_data.EMOJI_DATA
130+
128131
self.new_user_input = True
129132
self._start_presence_updates()
130133

zulipterminal/ui_tools/boxes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from bs4.element import NavigableString
1111
from urwid_readline import ReadlineEdit
1212

13-
from zulipterminal import emoji_data
1413
from zulipterminal.config.keys import is_command_key, keys_for_command
1514
from zulipterminal.config.symbols import (
1615
MESSAGE_CONTENT_MARKER, MESSAGE_HEADER_DIVIDER, QUOTED_TEXT_MARKER,
@@ -197,7 +196,7 @@ def autocomplete_streams(self, text: str, prefix_string: str
197196

198197
def autocomplete_emojis(self, text: str, prefix_string: str
199198
) -> Tuple[List[str], List[str]]:
200-
emoji_list = list(emoji_data.EMOJI_DATA.keys())
199+
emoji_list = list(self.model.emoji_data.keys())
201200
emojis = [emoji
202201
for emoji in emoji_list
203202
if match_emoji(emoji, text[1:])]

0 commit comments

Comments
 (0)