<commit_before>import json

import cherrypy
import mock

from mopidy.frontends.http import HttpFrontend

from tests import unittest


@mock.patch.object(cherrypy.engine, 'publish')
class HttpEventsTest(unittest.TestCase):
    def setUp(self):
        self.http = HttpFrontend(core=mock.Mock())

    def test_track_playback_paused_is_broadcasted(self, publish):
        publish.reset_mock()
        self.http.on_event('track_playback_paused', foo='bar')
        self.assertEqual(publish.call_args[0][0], 'websocket-broadcast')
        self.assertDictEqual(
            json.loads(str(publish.call_args[0][1])), {
                'event': 'track_playback_paused',
                'foo': 'bar',
            })<commit_msg>tests: Ignore http tests if cherrypy is missing<commit_after>import json

try:
    import cherrypy
except ImportError:
    cherrypy = False
import mock

from mopidy.exceptions import OptionalDependencyError
try:
    from mopidy.frontends.http import HttpFrontend
except OptionalDependencyError:
    pass

from tests import unittest


@unittest.skipUnless(cherrypy, 'cherrypy not found')
@mock.patch('cherrypy.engine.publish')
class HttpEventsTest(unittest.TestCase):
    def setUp(self):
        self.http = HttpFrontend(core=mock.Mock())

    def test_track_playback_paused_is_broadcasted(self, publish):
        publish.reset_mock()
        self.http.on_event('track_playback_paused', foo='bar')
        self.assertEqual(publish.call_args[0][0], 'websocket-broadcast')
        self.assertDictEqual(
            json.loads(str(publish.call_args[0][1])), {
                'event': 'track_playback_paused',
                'foo': 'bar',
            })
{'fraction_non_alphanumeric': 0.11084481725584182, 'fraction_numerical': 0.004793289394847214, 'mean_word_length': 3.4772117962466487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3813606', 'n_tokens_mistral': 532, 'n_tokens_neox': 513, 'n_words': 95}