Exemplo n.º 1
0
    def test_sqlalchemy_orm_exc(self):
        resp = ErrHandler.handler(orm_exc.NoResultFound())
        assert resp.status_code == 404
        data = json.loads(resp.get_data())
        assert data['message'] == u'源数据未找到'

        resp = ErrHandler.handler(orm_exc.UnmappedError())
        assert resp.status_code == 500
        data = json.loads(resp.get_data())
        assert data['message'] == u'服务器内部错误'
Exemplo n.º 2
0
 def test_others(self):
     resp = ErrHandler.handler(Exception('msg'))
     assert resp.status_code == 500
     data = json.loads(resp.get_data())
     assert data['message'] == u'服务器内部错误'
     # py27,py36 == "Exception('msg',)"
     # py37 == "Exception('msg')"
     assert data['detail'].startswith("Exception('msg'")
Exemplo n.º 3
0
 def test_hobbit_exception(self, app):
     resp = ErrHandler.handler(HobbitException('msg'))
     assert resp.status_code == 400
     data = json.loads(resp.get_data())
     assert data['message'] == 'msg'
     # py27,py36 == "Exception('msg',)"
     # py37 == "Exception('msg')"
     assert data['detail'].startswith("HobbitException('msg'")
Exemplo n.º 4
0
 def test_werkzeug_exceptions(self):
     resp = ErrHandler.handler(wkz_exc.Unauthorized())
     assert resp.status_code == 401
     data = json.loads(resp.get_data())
     assert data['message'] == u'未登录'
Exemplo n.º 5
0
 def test_assertion_error(self):
     resp = ErrHandler.handler(AssertionError('message'))
     assert resp.status_code == 422
     data = json.loads(resp.get_data())
     assert data['message'] == 'message'