フラスコクラスのビューにabort()があります。私はアボートが呼び出されたと主張することができますが、コンテキストマネージャの406コードにアクセスすることはできません。 WERKZEUGライブラリHTTPエラーでテスト中にFlaskのステータスコードをキャッチしていますか?
views.py
from flask.views import View
from flask import abort
class MyView(View):
def validate_request(self):
if self.accept_header not in self.allowed_types:
abort(406)
tests.py
from werkzeug.exceptions import HTTPException
def test_validate_request(self):
# Ensure that an invalid accept header type will return a 406
self.view.accept_header = 'foo/bar'
with self.assertRaises(HTTPException) as http_error:
self.view.validate_request()
self.assertEqual(http_error.???, 406)