Skip to content

Unit testing a delete endpoint causes ValueError: Invalid location argument: args #252

Description

@starkgate

I am trying to create a unit test for a DELETE endpoint. Here is simplified code:

app = Flask(__name__)
app.config.update({
    "TESTING": True,
})
api = Api(app)
api.add_resource(ObjectiveInterface, "/objectives")

client = app.test_client()
response = client.delete('/objectives?id=12') # also tried client.delete('/objectives', data={'id': '12'})

Which fails with the following error. I followed the guide here to write my test, and I believe the code is correct. Is this a bug with apispec or am I doing something wrong?

Error
Traceback (most recent call last):
  File "test_objective_interface.py", line 92, in test_delete
    response = self.client.delete('/objectives?id=12')
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "werkzeug\test.py", line 1156, in delete
    return self.open(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "flask\testing.py", line 223, in open
    response = super().open(
               ^^^^^^^^^^^^^
  File "werkzeug\test.py", line 1095, in open
    response = self.run_wsgi_app(request.environ, buffered=buffered)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "werkzeug\test.py", line 962, in run_wsgi_app
    rv = run_wsgi_app(self.application, environ, buffered=buffered)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "werkzeug\test.py", line 1243, in run_wsgi_app
    app_rv = app(environ, start_response)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 2551, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 2531, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_restful\__init__.py", line 271, in error_router
    return original_handler(e)
           ^^^^^^^^^^^^^^^^^^^
  File "flask_restful\__init__.py", line 268, in error_router
    return self.handle_error(e)
           ^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 2528, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 1825, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_restful\__init__.py", line 271, in error_router
    return original_handler(e)
           ^^^^^^^^^^^^^^^^^^^
  File "flask_restful\__init__.py", line 268, in error_router
    return self.handle_error(e)
           ^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_restful\__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\views.py", line 107, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask\views.py", line 188, in dispatch_request
    return current_app.ensure_sync(meth)(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_apispec\annotations.py", line 122, in wrapped
    return wrapper(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_apispec\wrapper.py", line 29, in __call__
    response = self.call_view(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "flask_apispec\wrapper.py", line 44, in call_view
    parsed = parser.parse(schema, location=option['kwargs']['location'])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "webargs\core.py", line 405, in parse
    location_data = self._load_location_data(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "webargs\core.py", line 210, in _load_location_data
    loader_func = self._get_loader(location)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "webargs\core.py", line 193, in _get_loader
    raise ValueError(f"Invalid location argument: {location}")
ValueError: Invalid location argument: args

Environment:

  • Python version: 3.11
  • Werkzeug version: 2.2.3
  • Flask version: 2.2.3
  • Flask restful: 0.3.9
  • Flask apispec: 0.11.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions