2016-06-03 02:46:57 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from zerver.lib.actions import get_realm, check_add_realm_emoji
|
|
|
|
from zerver.lib.test_helpers import AuthedTestCase
|
|
|
|
import ujson
|
|
|
|
|
|
|
|
class RealmEmojiTest(AuthedTestCase):
|
|
|
|
|
|
|
|
def test_list(self):
|
2016-06-04 19:54:34 +02:00
|
|
|
# type: () -> None
|
2016-06-03 02:46:57 +02:00
|
|
|
self.login("iago@zulip.com")
|
|
|
|
realm = get_realm('zulip.com')
|
|
|
|
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
2016-07-28 00:38:45 +02:00
|
|
|
result = self.client_get("/json/realm/emoji")
|
2016-06-03 02:46:57 +02:00
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
content = ujson.loads(result.content)
|
|
|
|
self.assertEqual(len(content["emoji"]), 1)
|
|
|
|
|
|
|
|
def test_upload(self):
|
2016-06-04 19:54:34 +02:00
|
|
|
# type: () -> None
|
2016-06-03 02:46:57 +02:00
|
|
|
self.login("iago@zulip.com")
|
|
|
|
data = {"name": "my_emoji", "url": "https://example.com/my_emoji"}
|
|
|
|
result = self.client_put("/json/realm/emoji", info=data)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(200, result.status_code)
|
|
|
|
|
2016-07-28 00:38:45 +02:00
|
|
|
result = self.client_get("/json/realm/emoji")
|
2016-06-03 02:46:57 +02:00
|
|
|
content = ujson.loads(result.content)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(content["emoji"]), 1)
|
|
|
|
|
|
|
|
def test_upload_exception(self):
|
2016-06-04 19:54:34 +02:00
|
|
|
# type: () -> None
|
2016-06-03 02:46:57 +02:00
|
|
|
self.login("iago@zulip.com")
|
|
|
|
data = {"name": "my_em*/oji", "url": "https://example.com/my_emoji"}
|
|
|
|
result = self.client_put("/json/realm/emoji", info=data)
|
2016-06-04 19:54:34 +02:00
|
|
|
self.assert_json_error(result, 'Invalid characters in Emoji name')
|
2016-06-03 02:46:57 +02:00
|
|
|
|
|
|
|
def test_delete(self):
|
2016-06-04 19:54:34 +02:00
|
|
|
# type: () -> None
|
2016-06-03 02:46:57 +02:00
|
|
|
self.login("iago@zulip.com")
|
|
|
|
realm = get_realm('zulip.com')
|
|
|
|
check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
|
|
|
|
result = self.client_delete("/json/realm/emoji/my_emoji")
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2016-07-28 00:38:45 +02:00
|
|
|
result = self.client_get("/json/realm/emoji")
|
2016-06-03 02:46:57 +02:00
|
|
|
content = ujson.loads(result.content)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(len(content["emoji"]), 0)
|