Raise InvalidException for empty required value

pull/26/head
Sheng 2018-08-26 15:40:08 +08:00
parent 5519a17016
commit 1a3880ecee
2 changed files with 7 additions and 7 deletions

View File

@ -87,17 +87,17 @@ class TestApp(AsyncHTTPTestCase):
body = 'hostname=&port=&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
self.assertIn(b'Missing argument hostname', response.body)
self.assertIn(b'Missing value hostname', response.body)
body = 'hostname=127.0.0.1&port=&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
self.assertIn(b'Missing argument port', response.body)
self.assertIn(b'Missing value port', response.body)
body = 'hostname=127.0.0.1&port=7000&username=&password'
response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400)
self.assertIn(b'Missing argument username', response.body)
self.assertIn(b'Missing value username', response.body)
def test_app_with_invalid_form_for_invalid_value(self):
body = 'hostname=127.0.0&port=22&username=&password'
@ -234,7 +234,7 @@ class TestApp(AsyncHTTPTestCase):
ws = yield tornado.websocket.websocket_connect(ws_url)
msg = yield ws.read_message()
self.assertIsNone(msg)
self.assertIn('Missing argument id', ws.close_reason)
self.assertIn('Missing value id', ws.close_reason)
@tornado.testing.gen_test
def test_app_with_correct_credentials_but_wrong_id(self):

View File

@ -55,7 +55,7 @@ class MixinHandler(object):
def get_value(self, name):
value = self.get_argument(name)
if not value:
raise tornado.web.MissingArgumentError(name)
raise InvalidException('Missing value {}'.format(name))
return value
def get_real_client_addr(self):
@ -261,8 +261,8 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
logging.info('Connected from {}:{}'.format(*self.src_addr))
try:
worker_id = self.get_value('id')
except tornado.web.MissingArgumentError as exc:
self.close(reason=exc.log_message)
except (tornado.web.MissingArgumentError, InvalidException) as exc:
self.close(reason=str(exc))
raise
else:
worker = workers.get(worker_id)