Commit 1a3880ec by Sheng

Raise InvalidException for empty required value

parent 5519a170
...@@ -87,17 +87,17 @@ class TestApp(AsyncHTTPTestCase): ...@@ -87,17 +87,17 @@ class TestApp(AsyncHTTPTestCase):
body = 'hostname=&port=&username=&password' body = 'hostname=&port=&username=&password'
response = self.fetch('/', method='POST', body=body) response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400) 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' body = 'hostname=127.0.0.1&port=&username=&password'
response = self.fetch('/', method='POST', body=body) response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400) 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' body = 'hostname=127.0.0.1&port=7000&username=&password'
response = self.fetch('/', method='POST', body=body) response = self.fetch('/', method='POST', body=body)
self.assertEqual(response.code, 400) 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): def test_app_with_invalid_form_for_invalid_value(self):
body = 'hostname=127.0.0&port=22&username=&password' body = 'hostname=127.0.0&port=22&username=&password'
...@@ -234,7 +234,7 @@ class TestApp(AsyncHTTPTestCase): ...@@ -234,7 +234,7 @@ class TestApp(AsyncHTTPTestCase):
ws = yield tornado.websocket.websocket_connect(ws_url) ws = yield tornado.websocket.websocket_connect(ws_url)
msg = yield ws.read_message() msg = yield ws.read_message()
self.assertIsNone(msg) self.assertIsNone(msg)
self.assertIn('Missing argument id', ws.close_reason) self.assertIn('Missing value id', ws.close_reason)
@tornado.testing.gen_test @tornado.testing.gen_test
def test_app_with_correct_credentials_but_wrong_id(self): def test_app_with_correct_credentials_but_wrong_id(self):
......
...@@ -55,7 +55,7 @@ class MixinHandler(object): ...@@ -55,7 +55,7 @@ class MixinHandler(object):
def get_value(self, name): def get_value(self, name):
value = self.get_argument(name) value = self.get_argument(name)
if not value: if not value:
raise tornado.web.MissingArgumentError(name) raise InvalidException('Missing value {}'.format(name))
return value return value
def get_real_client_addr(self): def get_real_client_addr(self):
...@@ -261,8 +261,8 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler): ...@@ -261,8 +261,8 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
logging.info('Connected from {}:{}'.format(*self.src_addr)) logging.info('Connected from {}:{}'.format(*self.src_addr))
try: try:
worker_id = self.get_value('id') worker_id = self.get_value('id')
except tornado.web.MissingArgumentError as exc: except (tornado.web.MissingArgumentError, InvalidException) as exc:
self.close(reason=exc.log_message) self.close(reason=str(exc))
raise raise
else: else:
worker = workers.get(worker_id) worker = workers.get(worker_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment