Skip to content

Instantly share code, notes, and snippets.

@risicle
Created August 21, 2022 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save risicle/2b87aedcdf3bb59fa4fbd245228ea070 to your computer and use it in GitHub Desktop.
Save risicle/2b87aedcdf3bb59fa4fbd245228ea070 to your computer and use it in GitHub Desktop.
flask-restful test failure
_________________ APITestCase.test_exception_header_forwarded __________________
self = <tests.test_api.APITestCase testMethod=test_exception_header_forwarded>
def test_exception_header_forwarded(self):
"""Test that HTTPException's headers are extended properly"""
app = Flask(__name__)
app.config['DEBUG'] = True
api = flask_restful.Api(app)
class NotModified(HTTPException):
code = 304
def __init__(self, etag, *args, **kwargs):
super(NotModified, self).__init__(*args, **kwargs)
self.etag = quote_etag(etag)
def get_headers(self, *args, **kwargs):
"""Get a list of headers."""
return [('ETag', self.etag)]
class Foo1(flask_restful.Resource):
def get(self):
flask_abort(304, etag='myETag')
api.add_resource(Foo1, '/foo')
_aborter.mapping.update({304: NotModified})
with app.test_client() as client:
> foo = client.get('/foo')
tests/test_api.py:817:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/nix/store/n4rlpm3bf4y51vdcqxsr0hjxv2pmkdas-python3.9-werkzeug-2.2.2/lib/python3.9/site-packages/werkzeug/test.py:1140: in get
return self.open(*args, **kw)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/testing.py:223: in open
response = super().open(
/nix/store/n4rlpm3bf4y51vdcqxsr0hjxv2pmkdas-python3.9-werkzeug-2.2.2/lib/python3.9/site-packages/werkzeug/test.py:1094: in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
/nix/store/n4rlpm3bf4y51vdcqxsr0hjxv2pmkdas-python3.9-werkzeug-2.2.2/lib/python3.9/site-packages/werkzeug/test.py:961: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
/nix/store/n4rlpm3bf4y51vdcqxsr0hjxv2pmkdas-python3.9-werkzeug-2.2.2/lib/python3.9/site-packages/werkzeug/test.py:1242: in run_wsgi_app
app_rv = app(environ, start_response)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:2548: in __call__
return self.wsgi_app(environ, start_response)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:2528: in wsgi_app
response = self.handle_exception(e)
flask_restful/__init__.py:271: in error_router
return original_handler(e)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:2525: in wsgi_app
response = self.full_dispatch_request()
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:1822: in full_dispatch_request
rv = self.handle_user_exception(e)
flask_restful/__init__.py:271: in error_router
return original_handler(e)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:1820: in full_dispatch_request
rv = self.dispatch_request()
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/app.py:1796: in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
flask_restful/__init__.py:467: in wrapper
resp = resource(*args, **kwargs)
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/views.py:107: in view
return current_app.ensure_sync(self.dispatch_request)(**kwargs)
flask_restful/__init__.py:582: in dispatch_request
resp = meth(*args, **kwargs)
tests/test_api.py:811: in get
flask_abort(304, etag='myETag')
/nix/store/mizjj4ilcgzrbz0nq96nzr9gwk4yiicd-python3.9-flask-2.2.2/lib/python3.9/site-packages/flask/helpers.py:310: in abort
current_app.aborter(code, *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <werkzeug.exceptions.Aborter object at 0x7ffff5679cd0>, code = 304
args = (), kwargs = {'etag': 'myETag'}
Response = <class 'werkzeug.sansio.response.Response'>
def __call__(
self, code: t.Union[int, "Response"], *args: t.Any, **kwargs: t.Any
) -> "te.NoReturn":
from .sansio.response import Response
if isinstance(code, Response):
raise HTTPException(response=code)
if code not in self.mapping:
> raise LookupError(f"no exception for {code!r}")
E LookupError: no exception for 304
/nix/store/n4rlpm3bf4y51vdcqxsr0hjxv2pmkdas-python3.9-werkzeug-2.2.2/lib/python3.9/site-packages/werkzeug/exceptions.py:862: LookupError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment