From b6e1a7d731c8fb0b7462d5e429922385f187eeb2 Mon Sep 17 00:00:00 2001 From: Manu K Paul Date: Thu, 26 Nov 2020 18:41:27 +0530 Subject: [PATCH] model: Fetch realm emoji using events Fetching emoji using events ensures that realm emoji updates are not missed. Initial state of realm emoji is updated from initial_data. Added key 'realm_emoji' to initial_data to fix key error while running pytest. Added new tests for the handler of emoji update event. --- tests/model/test_model.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/model/test_model.py b/tests/model/test_model.py index 3eec48aacc..4c914719bb 100644 --- a/tests/model/test_model.py +++ b/tests/model/test_model.py @@ -1887,3 +1887,35 @@ def test_process_realm_emoji_data(self, mocker, model, fetched_custom_emojis = model.process_realm_emoji_data() assert fetched_custom_emojis == custom_emojis + + @pytest.mark.parametrize('response', [ + ({ + "last_event_id": -1, + "msg": "", + "queue_id": "1517975029:0", + "realm_emoji": { + "100": { + "id": "100", + "name": "urwid", + "deactivated": True + }, + "1": { + "id": "1", + "name": "green_tick", + "deactivated": False + } + }, + "result": "success", + "zulip_feature_level": 2, + "zulip_version": "2.1.0" + }) + ]) + def test__handle_update_emoji_event(self, mocker, model, + response): + model._handle_update_emoji_event(response) + # For an already active emoji which has been deactivated + with pytest.raises(KeyError): + model.active_emoji_data['urwid'] + # For a newly created custom emoji. + new_added_emoji = model.active_emoji_data['green_tick']['code'] + assert new_added_emoji == response['realm_emoji']['1']['id']