class MpdDispatcherTest(unittest.TestCase): def setUp(self): # noqa: N802 config = { 'mpd': { 'password': None, 'command_blacklist': ['disabled'], } } self.backend = dummy_backend.create_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config) def tearDown(self): # noqa: N802 pykka.ActorRegistry.stop_all() def test_call_handler_for_unknown_command_raises_exception(self): with self.assertRaises(MpdAckError) as cm: self.dispatcher._call_handler('an_unknown_command with args') self.assertEqual(cm.exception.get_mpd_ack(), 'ACK [5@0] {} unknown command "an_unknown_command"') def test_handling_unknown_request_yields_error(self): result = self.dispatcher.handle_request('an unhandled request') self.assertEqual(result[0], 'ACK [5@0] {} unknown command "an"') def test_handling_blacklisted_command(self): result = self.dispatcher.handle_request('disabled') self.assertEqual( result[0], 'ACK [0@0] {disabled} "disabled" has been ' 'disabled in the server')
class MpdDispatcherTest(unittest.TestCase): def setUp(self): # noqa: N802 config = { 'mpd': { 'password': None, 'command_blacklist': ['disabled'], } } self.backend = dummy_backend.create_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config) def tearDown(self): # noqa: N802 pykka.ActorRegistry.stop_all() def test_call_handler_for_unknown_command_raises_exception(self): with self.assertRaises(MpdAckError) as cm: self.dispatcher._call_handler('an_unknown_command with args') self.assertEqual( cm.exception.get_mpd_ack(), 'ACK [5@0] {} unknown command "an_unknown_command"') def test_handling_unknown_request_yields_error(self): result = self.dispatcher.handle_request('an unhandled request') self.assertEqual(result[0], 'ACK [5@0] {} unknown command "an"') def test_handling_blacklisted_command(self): result = self.dispatcher.handle_request('disabled') self.assertEqual(result[0], 'ACK [0@0] {disabled} "disabled" has been ' 'disabled in the server')
class MpdDispatcherTest(unittest.TestCase): def setUp(self): config = { 'mpd': { 'password': None, } } self.backend = dummy.create_dummy_backend_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config) def tearDown(self): pykka.ActorRegistry.stop_all() def test_call_handler_for_unknown_command_raises_exception(self): try: self.dispatcher._call_handler('an_unknown_command with args') self.fail('Should raise exception') except MpdAckError as e: self.assertEqual( e.get_mpd_ack(), 'ACK [5@0] {} unknown command "an_unknown_command"') def test_handling_unknown_request_yields_error(self): result = self.dispatcher.handle_request('an unhandled request') self.assertEqual(result[0], 'ACK [5@0] {} unknown command "an"')
def setUp(self): config = { 'mpd': { 'password': None, } } self.backend = dummy.create_dummy_backend_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config)
def setUp(self): # noqa: N802 config = { 'mpd': { 'password': None, 'command_blacklist': ['disabled'], } } self.backend = dummy_backend.create_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config)
class MpdDispatcherTest(unittest.TestCase): def setUp(self): config = { 'mpd': { 'password': None, } } self.backend = dummy.create_dummy_backend_proxy() self.core = core.Core.start(backends=[self.backend]).proxy() self.dispatcher = MpdDispatcher(config=config) def tearDown(self): pykka.ActorRegistry.stop_all() def test_register_same_pattern_twice_fails(self): func = lambda: None try: handle_request('a pattern')(func) handle_request('a pattern')(func) self.fail('Registering a pattern twice shoulde raise ValueError') except ValueError: pass def test_finding_handler_for_unknown_command_raises_exception(self): try: self.dispatcher._find_handler('an_unknown_command with args') self.fail('Should raise exception') except MpdAckError as e: self.assertEqual( e.get_mpd_ack(), 'ACK [5@0] {} unknown command "an_unknown_command"') def test_find_handler_for_known_command_returns_handler_and_kwargs(self): expected_handler = lambda x: None request_handlers['known_command (?P<arg1>.+)'] = \ expected_handler (handler, kwargs) = self.dispatcher._find_handler( 'known_command an_arg') self.assertEqual(handler, expected_handler) self.assertIn('arg1', kwargs) self.assertEqual(kwargs['arg1'], 'an_arg') def test_handling_unknown_request_yields_error(self): result = self.dispatcher.handle_request('an unhandled request') self.assertEqual(result[0], 'ACK [5@0] {} unknown command "an"') def test_handling_known_request(self): expected = 'magic' request_handlers['known request'] = lambda x: expected result = self.dispatcher.handle_request('known request') self.assertIn('OK', result) self.assertIn(expected, result)