From be5c90c217ad4480bb2391e918d07a3f9e2a88d6 Mon Sep 17 00:00:00 2001
From: Kevin Mehall
Date: Thu, 22 Aug 2013 17:55:37 -0400
Subject: [PATCH] Add test for realm-specific emoji
(imported from commit 2148038b300b71afe0a7517709ed0404536b69fd)
---
zerver/tests.py | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/zerver/tests.py b/zerver/tests.py
index f675f5c449..1b33f5fc8f 100644
--- a/zerver/tests.py
+++ b/zerver/tests.py
@@ -10,13 +10,14 @@ from django.db.models import Q
from zerver.models import Message, UserProfile, Stream, Recipient, Subscription, \
get_display_recipient, Realm, Client, \
PreregistrationUser, UserMessage, \
- get_user_profile_by_email, email_to_domain
+ get_user_profile_by_email, email_to_domain, get_realm
from zerver.tornadoviews import json_get_updates, api_get_messages
from zerver.decorator import RespondAsynchronously, \
RequestVariableConversionError, profiled, JsonableError
from zerver.lib.initial_password import initial_password
from zerver.lib.actions import check_send_message, gather_subscriptions, \
- create_stream_if_needed, do_add_subscription, compute_mit_user_fullname
+ create_stream_if_needed, do_add_subscription, compute_mit_user_fullname, \
+ do_add_realm_emoji, do_remove_realm_emoji
from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule
from zerver.lib import bugdown
from zerver.lib.cache import bounce_key_prefix_for_testing
@@ -2678,6 +2679,23 @@ xxxxxxx
\nxxxxxxx xxxxx xxxx xxxxx:
\nxxxxxx
: xxx
emoji_img(':smile:') +
'
')
+ def test_realm_emoji(self):
+ def emoji_img(name, url):
+ return '' % (name, url, name)
+
+ zulip_realm = get_realm('zulip.com')
+ url = "https://zulip.com/test_realm_emoji.png"
+ do_add_realm_emoji(zulip_realm, "test", url)
+
+ # Needs to mock an actual message because that's how bugdown obtains the realm
+ msg = Message(sender=get_user_profile_by_email("hamlet@zulip.com"))
+ converted = bugdown.convert(":test:", "zulip.com", msg)
+ self.assertEqual(converted, '%s
' %(emoji_img(':test:', url)))
+
+ do_remove_realm_emoji(zulip_realm, 'test')
+ converted = bugdown.convert(":test:", "zulip.com", msg)
+ self.assertEqual(converted, ':test:
')
+
def test_multiline_strong(self):
msg = "Welcome to **the jungle**"
converted = bugdown_convert(msg)