From eb85f92d96bdc653a8964b335764dc5165e9b5d5 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 22 Jan 2014 23:05:13 +0100 Subject: [PATCH] mpd: Store auth required and if command should be listed --- mopidy/mpd/protocol/__init__.py | 10 ++++++---- tests/mpd/test_commands.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/mopidy/mpd/protocol/__init__.py b/mopidy/mpd/protocol/__init__.py index 03ac6dda..06a1b3ab 100644 --- a/mopidy/mpd/protocol/__init__.py +++ b/mopidy/mpd/protocol/__init__.py @@ -112,10 +112,10 @@ class Commands(object): def __init__(self): self.handlers = {} - def add(self, command, **validators): + def add(self, name, auth_required=True, list_command=True, **validators): def wrapper(func): - if command in self.handlers: - raise Exception('%s already registered' % command) + if name in self.handlers: + raise Exception('%s already registered' % name) args, varargs, keywords, defaults = inspect.getargspec(func) defaults = dict(zip(args[-len(defaults or []):], defaults or [])) @@ -143,7 +143,9 @@ class Commands(object): callargs[key] = validators[key](value) return func(**callargs) - self.handlers[command] = validate + validate.auth_required = auth_required + validate.list_command = list_command + self.handlers[name] = validate return func return wrapper diff --git a/tests/mpd/test_commands.py b/tests/mpd/test_commands.py index 0d2d2ad3..f0f04bb7 100644 --- a/tests/mpd/test_commands.py +++ b/tests/mpd/test_commands.py @@ -185,3 +185,21 @@ class TestCommands(unittest.TestCase): with self.assertRaises(TypeError): func = lambda context: True self.commands.add('bar', context=lambda v: v)(func) + + def test_auth_required_gets_stored(self): + func1 = lambda context: context + func2 = lambda context: context + self.commands.add('foo')(func1) + self.commands.add('bar', auth_required=False)(func2) + + self.assertTrue(self.commands.handlers['foo'].auth_required) + self.assertFalse(self.commands.handlers['bar'].auth_required) + + def test_list_command_gets_stored(self): + func1 = lambda context: context + func2 = lambda context: context + self.commands.add('foo')(func1) + self.commands.add('bar', list_command=False)(func2) + + self.assertTrue(self.commands.handlers['foo'].list_command) + self.assertFalse(self.commands.handlers['bar'].list_command)