MPD: Implement 'commands' command

This commit is contained in:
Stein Magnus Jodal 2010-06-20 21:25:46 +02:00
parent c6cd2ba564
commit d00c47ec88
2 changed files with 18 additions and 4 deletions

View File

@ -1090,8 +1090,16 @@ class MpdFrontend(object):
``commands`` ``commands``
Shows which commands the current user has access to. Shows which commands the current user has access to.
As permissions is not implemented, any user has access to all commands.
""" """
pass # TODO commands = set()
for command_pattern in _request_handlers.keys():
match = re.search('([a-z_]+)', command_pattern)
if match is not None:
commands.add(match.group())
commands = sorted(list(commands))
return [('command', command) for command in commands]
@handle_pattern(r'^decoders$') @handle_pattern(r'^decoders$')
def _reflection_decoders(self): def _reflection_decoders(self):
@ -1120,8 +1128,10 @@ class MpdFrontend(object):
``notcommands`` ``notcommands``
Shows which commands the current user does not have access to. Shows which commands the current user does not have access to.
As permissions is not implemented, any user has access to all commands.
""" """
pass # TODO pass
@handle_pattern(r'^tagtypes$') @handle_pattern(r'^tagtypes$')
def _reflection_tagtypes(self): def _reflection_tagtypes(self):

View File

@ -1161,16 +1161,20 @@ class ReflectionHandlerTest(unittest.TestCase):
self.b = DummyBackend(mixer=self.m) self.b = DummyBackend(mixer=self.m)
self.h = frontend.MpdFrontend(backend=self.b) self.h = frontend.MpdFrontend(backend=self.b)
def test_commands(self): def test_commands_returns_list_of_all_commands(self):
result = self.h.handle_request(u'commands') result = self.h.handle_request(u'commands')
self.assert_(u'command: commands' in result)
self.assert_(u'command: play' in result)
self.assert_(u'command: status' in result)
self.assert_(u'OK' in result) self.assert_(u'OK' in result)
def test_decoders(self): def test_decoders(self):
result = self.h.handle_request(u'decoders') result = self.h.handle_request(u'decoders')
self.assert_(u'ACK Not implemented' in result) self.assert_(u'ACK Not implemented' in result)
def test_notcommands(self): def test_notcommands_returns_only_ok(self):
result = self.h.handle_request(u'notcommands') result = self.h.handle_request(u'notcommands')
self.assertEqual(1, len(result))
self.assert_(u'OK' in result) self.assert_(u'OK' in result)
def test_tagtypes(self): def test_tagtypes(self):