我有一个单元测试,如果没有像这样进行身份验证,则测试一个 api 点是否不可访问:
def test_endpoint_get_unauth(self):
r = self.get('/api/endpoint/1')
self.assertStatusCode(r, 401)
测试通过了,但nosetests/unittest 仍然向我显示一个错误,即引发异常说“未授权”。有没有办法阻止这一切?
完整日志:
ERROR in views [/myenv/lib/python2.7/site-packages/flask_restless/views.py:115]:
Not Authorized
--------------------------------------------------------------------------------
Traceback (most recent call last):
File "/myapp/myenv/lib/python2.7/site-packages/flask_restless/views.py", line 113, in decorator
return func(*args, **kw)
File "/myapp/myenv/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/myapp/myenv/lib/python2.7/site-packages/flask/views.py", line 149, in dispatch_request
return meth(*args, **kwargs)
File "/myapp/myenv/lib/python2.7/site-packages/flask_restless/views.py", line 989, in get
preprocessor(instance_id=instid)
File "/myapp/app/api/api.py", line 16, in check_auth
raise ProcessingException(message='Not Authorized', status_code=401)
ProcessingException
................
----------------------------------------------------------------------
Ran 16 tests in 15.788s
OK