parent
a650cc08c0
commit
93bf3ea918
@ -138,7 +138,13 @@ class Commands(object):
|
||||
def validate(*args, **kwargs):
|
||||
if varargs:
|
||||
return func(*args, **kwargs)
|
||||
callargs = inspect.getcallargs(func, *args, **kwargs)
|
||||
|
||||
try:
|
||||
callargs = inspect.getcallargs(func, *args, **kwargs)
|
||||
except TypeError:
|
||||
raise exceptions.MpdArgError(
|
||||
'wrong number of arguments for "%s"' % name)
|
||||
|
||||
for key, value in callargs.items():
|
||||
default = defaults.get(key, object())
|
||||
if key in validators and value != default:
|
||||
@ -146,6 +152,7 @@ class Commands(object):
|
||||
callargs[key] = validators[key](value)
|
||||
except ValueError:
|
||||
raise exceptions.MpdArgError('incorrect arguments')
|
||||
|
||||
return func(**callargs)
|
||||
|
||||
validate.auth_required = auth_required
|
||||
|
||||
@ -19,6 +19,12 @@ class AuthenticationActiveTest(protocol.BaseTestCase):
|
||||
self.assertFalse(self.dispatcher.authenticated)
|
||||
self.assertEqualResponse('ACK [3@0] {password} incorrect password')
|
||||
|
||||
def test_authentication_without_password_fails(self):
|
||||
self.sendRequest('password')
|
||||
self.assertFalse(self.dispatcher.authenticated)
|
||||
self.assertEqualResponse(
|
||||
'ACK [2@0] {password} wrong number of arguments for "password"')
|
||||
|
||||
def test_anything_when_not_authenticated_should_fail(self):
|
||||
self.sendRequest('any request at all')
|
||||
self.assertFalse(self.dispatcher.authenticated)
|
||||
|
||||
@ -169,15 +169,15 @@ class TestCommands(unittest.TestCase):
|
||||
|
||||
def test_call_incorrect_args(self):
|
||||
self.commands.add('foo')(lambda context: context)
|
||||
with self.assertRaises(TypeError):
|
||||
with self.assertRaises(exceptions.MpdArgError):
|
||||
self.commands.call(['foo', 'bar'])
|
||||
|
||||
self.commands.add('bar')(lambda context, required: context)
|
||||
with self.assertRaises(TypeError):
|
||||
with self.assertRaises(exceptions.MpdArgError):
|
||||
self.commands.call(['bar', 'bar', 'baz'])
|
||||
|
||||
self.commands.add('baz')(lambda context, optional=None: context)
|
||||
with self.assertRaises(TypeError):
|
||||
with self.assertRaises(exceptions.MpdArgError):
|
||||
self.commands.call(['baz', 'bar', 'baz'])
|
||||
|
||||
def test_validator_gets_applied_to_required_arg(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user