<commit_before># -*- 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 ZulipTestCase
import ujson

class RealmEmojiTest(ZulipTestCase):

    def test_list(self):
        # type: () -> None
        self.login("<EMAIL>")
        realm = get_realm('zulip.com')
        check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
        result = self.client_get("/json/realm/emoji")
        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):
        # type: () -> None
        self.login("<EMAIL>")
        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)

        result = self.client_get("/json/realm/emoji")
        content = ujson.loads(result.content)
        self.assert_json_success(result)
        self.assertEqual(len(content["emoji"]), 1)

    def test_upload_exception(self):
        # type: () -> None
        self.login("<EMAIL>")
        data = {"name": "my_em*/oji", "url": "https://example.com/my_emoji"}
        result = self.client_put("/json/realm/emoji", info=data)
        self.assert_json_error(result, 'Invalid characters in Emoji name')

    def test_delete(self):
        # type: () -> None
        self.login("<EMAIL>")
        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)

        result = self.client_get("/json/realm/emoji")
        content = ujson.loads(result.content)
        self.assert_json_success(result)
        self.assertEqual(len(content["emoji"]), 0)
<commit_msg>tests: Add coverage for RealmEmoji.__unicode__().<commit_after># -*- 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 ZulipTestCase
from zerver.models import RealmEmoji
import ujson

class RealmEmojiTest(ZulipTestCase):

    def test_list(self):
        # type: () -> None
        self.login("<EMAIL>")
        realm = get_realm('zulip.com')
        check_add_realm_emoji(realm, "my_emoji", "https://example.com/my_emoji")
        result = self.client_get("/json/realm/emoji")
        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):
        # type: () -> None
        self.login("<EMAIL>")
        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)

        result = self.client_get("/json/realm/emoji")
        content = ujson.loads(result.content)
        self.assert_json_success(result)
        self.assertEqual(len(content["emoji"]), 1)

        realm_emoji = RealmEmoji.objects.get(realm=get_realm('zulip.com'))
        self.assertEqual(
            str(realm_emoji),
            '<RealmEmoji(zulip.com): my_emoji https://example.com/my_emoji>'
        )

    def test_upload_exception(self):
        # type: () -> None
        self.login("<EMAIL>")
        data = {"name": "my_em*/oji", "url": "https://example.com/my_emoji"}
        result = self.client_put("/json/realm/emoji", info=data)
        self.assert_json_error(result, 'Invalid characters in Emoji name')

    def test_delete(self):
        # type: () -> None
        self.login("<EMAIL>")
        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)

        result = self.client_get("/json/realm/emoji")
        content = ujson.loads(result.content)
        self.assert_json_success(result)
        self.assertEqual(len(content["emoji"]), 0)

{'fraction_non_alphanumeric': 0.14496088357109987, 'fraction_numerical': 0.004601932811780948, 'mean_word_length': 2.999080036798528, 'pattern_counts': {'":': 8, '<': 12, '<?xml version=': 0, '>': 20, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7369851', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1449, 'n_words': 217}