Description: Add missing location= when calling add_argument
 The new werkzeug version 2.2.2 mandates location= when calling
 parser.add_argument().
Author: Rene Luria <rene.luria@infomaniak.com>
Bug-Debian: https://bugs.debian.org/1024913
Forwarded: no
Last-Update: 2022-12-16

--- flask-restful.orig/tests/test_reqparse.py
+++ flask-restful/tests/test_reqparse.py
@@ -227,7 +227,7 @@
     def test_parse_unicode(self):
         req = Request.from_values("/bubble?foo=barß")
         parser = RequestParser()
-        parser.add_argument("foo")
+        parser.add_argument("foo", location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], u"barß")
@@ -236,22 +236,12 @@
         app = Flask(__name__)
 
         parser = RequestParser()
-        parser.add_argument("foo")
+        parser.add_argument("foo", location="args")
 
         with app.test_request_context('/bubble?foo=barß'):
             args = parser.parse_args()
             self.assertEqual(args['foo'], u"barß")
 
-    def test_json_location(self):
-        app = Flask(__name__)
-
-        parser = RequestParser()
-        parser.add_argument("foo", location="json", store_missing=True)
-
-        with app.test_request_context('/bubble', method="post"):
-            args = parser.parse_args()
-            self.assertEqual(args['foo'], None)
-
     def test_get_json_location(self):
         app = Flask(__name__)
 
@@ -269,7 +259,7 @@
 
         parser = RequestParser()
         parser.add_argument("foo", ignore=True, type=int, action="append",
-                            store_missing=True),
+                            store_missing=True, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], None)
@@ -278,7 +268,7 @@
         req = Request.from_values("/bubble?")
 
         parser = RequestParser()
-        parser.add_argument("foo", action="append", store_missing=True),
+        parser.add_argument("foo", action="append", store_missing=True, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], None)
@@ -287,7 +277,7 @@
         req = Request.from_values("/bubble?foo=bar&foo=bat")
 
         parser = RequestParser()
-        parser.add_argument("foo", action="append"),
+        parser.add_argument("foo", action="append", location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ["bar", "bat"])
@@ -296,7 +286,7 @@
         req = Request.from_values("/bubble?foo=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo", action="append"),
+        parser.add_argument("foo", action="append", location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ["bar"])
@@ -305,7 +295,7 @@
         req = Request.from_values("/bubble?foo=bar&foo=bar2")
 
         parser = RequestParser()
-        parser.add_argument("foo", action="append"),
+        parser.add_argument("foo", action="append", location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ["bar", "bar2"])
@@ -326,7 +316,7 @@
         req = Request.from_values("/bubble?foo=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo", dest="bat")
+        parser.add_argument("foo", dest="bat", location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['bat'], "bar")
@@ -335,7 +325,7 @@
         req = Request.from_values("/bubble?foo>=bar&foo<=bat&foo=foo")
 
         parser = RequestParser()
-        parser.add_argument("foo", operators=[">=", "<=", "="], action="append"),
+        parser.add_argument("foo", operators=[">=", "<=", "="], action="append", location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ["bar", "bat", "foo"])
@@ -344,7 +334,7 @@
         req = Request.from_values("/bubble?foo>=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo", operators=[">="])
+        parser.add_argument("foo", operators=[">="], location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
@@ -353,13 +343,13 @@
         app = Flask(__name__)
         with app.app_context():
             parser = RequestParser()
-            parser.add_argument("foo", type=int),
+            parser.add_argument("foo", type=int, location="args"),
 
             self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(Request.from_values("/bubble?foo=bar")))
 
     def test_parse_foo_operators_ignore(self):
         parser = RequestParser()
-        parser.add_argument("foo", ignore=True, store_missing=True)
+        parser.add_argument("foo", ignore=True, store_missing=True, location="args")
 
         args = parser.parse_args(Request.from_values("/bubble"))
         self.assertEqual(args['foo'], None)
@@ -369,41 +359,41 @@
         req = Request.from_values("/bubble?foo<=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo", type=mock_type, operators=["<="])
+        parser.add_argument("foo", type=mock_type, operators=["<="], location="args")
 
         parser.parse_args(req)
         mock_type.assert_called_with("bar", "foo", "<=")
 
     def test_parse_lte_gte_append(self):
         parser = RequestParser()
-        parser.add_argument("foo", operators=["<=", "="], action="append")
+        parser.add_argument("foo", operators=["<=", "="], action="append", location="args")
 
         args = parser.parse_args(Request.from_values("/bubble?foo<=bar"))
         self.assertEqual(args['foo'], ["bar"])
 
     def test_parse_lte_gte_missing(self):
         parser = RequestParser()
-        parser.add_argument("foo", operators=["<=", "="])
+        parser.add_argument("foo", operators=["<=", "="], location="args")
         args = parser.parse_args(Request.from_values("/bubble?foo<=bar"))
         self.assertEqual(args['foo'], "bar")
 
     def test_parse_eq_other(self):
         parser = RequestParser()
-        parser.add_argument("foo"),
+        parser.add_argument("foo", location="args"),
         args = parser.parse_args(Request.from_values("/bubble?foo=bar&foo=bat"))
         self.assertEqual(args['foo'], "bar")
 
     def test_parse_eq(self):
         req = Request.from_values("/bubble?foo=bar")
         parser = RequestParser()
-        parser.add_argument("foo"),
+        parser.add_argument("foo", location="args"),
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
 
     def test_parse_lte(self):
         req = Request.from_values("/bubble?foo<=bar")
         parser = RequestParser()
-        parser.add_argument("foo", operators=["<="])
+        parser.add_argument("foo", operators=["<="], location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
@@ -486,7 +476,7 @@
         req = Request.from_values("/bubble")
         parser = RequestParser()
         parser.add_argument("foo", default="bar", action="append",
-                            store_missing=True)
+                            store_missing=True, location="args")
 
         args = parser.parse_args(req)
 
@@ -496,7 +486,7 @@
         req = Request.from_values("/bubble")
 
         parser = RequestParser()
-        parser.add_argument("foo", default="bar", store_missing=True)
+        parser.add_argument("foo", default="bar", store_missing=True, location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
@@ -505,7 +495,7 @@
         req = Request.from_values("/bubble")
 
         parser = RequestParser()
-        parser.add_argument("foo", default=lambda: "bar", store_missing=True)
+        parser.add_argument("foo", default=lambda: "bar", store_missing=True, location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
@@ -514,7 +504,7 @@
         req = Request.from_values("/bubble?foo=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo"),
+        parser.add_argument("foo", location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bar")
@@ -523,7 +513,7 @@
         req = Request.from_values("/bubble")
 
         parser = RequestParser()
-        parser.add_argument("foo")
+        parser.add_argument("foo", location="args")
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], None)
@@ -532,7 +522,7 @@
         req = Request.from_values("/bubble")
 
         parser = RequestParser()
-        parser.add_argument("foo", store_missing=False)
+        parser.add_argument("foo", store_missing=False, location="args")
 
         args = parser.parse_args(req)
         self.assertFalse('foo' in args)
@@ -541,7 +531,7 @@
         req = Request.from_values("/bubble?foo=bat")
 
         parser = RequestParser()
-        parser.add_argument("foo", choices=["bat"]),
+        parser.add_argument("foo", choices=["bat"], location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "bat")
@@ -552,7 +542,7 @@
             req = Request.from_values("/bubble?foo=bar")
 
             parser = RequestParser()
-            parser.add_argument("foo", choices=["bat"]),
+            parser.add_argument("foo", choices=["bat"], location="args"),
 
             self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(req))
 
@@ -562,7 +552,7 @@
             req = Request.from_values("/bubble?foo=BAT")
 
             parser = RequestParser()
-            parser.add_argument("foo", choices=["bat"], case_sensitive=True),
+            parser.add_argument("foo", choices=["bat"], case_sensitive=True, location="args"),
 
             self.assertRaises(exceptions.BadRequest, lambda: parser.parse_args(req))
 
@@ -570,7 +560,7 @@
         req = Request.from_values("/bubble?foo=BAT")
 
         parser = RequestParser()
-        parser.add_argument("foo", choices=["bat"], case_sensitive=False),
+        parser.add_argument("foo", choices=["bat"], case_sensitive=False, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual('bat', args.get('foo'))
@@ -579,7 +569,7 @@
         req = Request.from_values("/bubble?foo=bat")
 
         parser = RequestParser()
-        parser.add_argument("foo", choices=["BAT"], case_sensitive=False),
+        parser.add_argument("foo", choices=["BAT"], case_sensitive=False, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual('bat', args.get('foo'))
@@ -588,7 +578,7 @@
         req = Request.from_values("/bubble?foo=bar")
 
         parser = RequestParser()
-        parser.add_argument("foo", type=int, ignore=True, store_missing=True),
+        parser.add_argument("foo", type=int, ignore=True, store_missing=True, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], None)
@@ -630,7 +620,7 @@
         req = Request.from_values("/bubble?foo=1")
 
         parser = RequestParser()
-        parser.add_argument("foo", type=lambda x: x, required=False),
+        parser.add_argument("foo", type=lambda x: x, required=False, location="args"),
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], "1")
@@ -713,7 +703,7 @@
     def test_passing_arguments_object(self):
         req = Request.from_values("/bubble?foo=bar")
         parser = RequestParser()
-        parser.add_argument(Argument("foo"))
+        parser.add_argument(Argument("foo", location="args"))
 
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], u"bar")
@@ -753,7 +743,7 @@
     def test_request_parser_copy(self):
         req = Request.from_values("/bubble?foo=101&bar=baz")
         parser = RequestParser()
-        foo_arg = Argument('foo', type=int)
+        foo_arg = Argument('foo', type=int, location="args")
         parser.args.append(foo_arg)
         parser_copy = parser.copy()
 
@@ -762,7 +752,7 @@
         self.assertFalse(foo_arg in parser_copy.args)
 
         # Args added to new parser should not be added to the original
-        bar_arg = Argument('bar')
+        bar_arg = Argument('bar', location="args")
         parser_copy.args.append(bar_arg)
         self.assertFalse(bar_arg in parser.args)
 
@@ -780,9 +770,9 @@
     def test_request_parser_replace_argument(self):
         req = Request.from_values("/bubble?foo=baz")
         parser = RequestParser()
-        parser.add_argument('foo', type=int)
+        parser.add_argument('foo', type=int, location="args")
         parser_copy = parser.copy()
-        parser_copy.replace_argument('foo')
+        parser_copy.replace_argument('foo', location="args")
 
         args = parser_copy.parse_args(req)
         self.assertEqual(args['foo'], u'baz')
@@ -792,8 +782,8 @@
         app = Flask(__name__)
 
         parser = RequestParser()
-        parser.add_argument('foo', type=int)
-        parser.add_argument('baz', type=int)
+        parser.add_argument('foo', type=int, location="args")
+        parser.add_argument('baz', type=int, location="json")
         with app.test_request_context('/bubble?foo=1', method="post",
                                       data=json.dumps({"baz": 2}),
                                       content_type='application/json'):
@@ -828,54 +818,54 @@
         self.assertEqual(args, {})
 
     def test_strict_parsing_on(self):
-        req = Request.from_values("/bubble?foo=baz")
+        req = Request.from_values("/bubble?foo=baz", headers={'Content-Type': 'application/json'})
         parser = RequestParser()
         self.assertRaises(exceptions.BadRequest, parser.parse_args, req, strict=True)
 
     def test_strict_parsing_off_partial_hit(self):
-        req = Request.from_values("/bubble?foo=1&bar=bees&n=22")
+        req = Request.from_values("/bubble?foo=1&bar=bees&n=22", headers={'Content-Type': 'application/json'})
         parser = RequestParser()
-        parser.add_argument('foo', type=int)
+        parser.add_argument('foo', type=int, location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], 1)
 
     def test_strict_parsing_on_partial_hit(self):
-        req = Request.from_values("/bubble?foo=1&bar=bees&n=22")
+        req = Request.from_values("/bubble?foo=1&bar=bees&n=22", headers={'Content-Type': 'application/json'})
         parser = RequestParser()
-        parser.add_argument('foo', type=int)
+        parser.add_argument('foo', type=int, location="args")
         self.assertRaises(exceptions.BadRequest, parser.parse_args, req, strict=True)
 
     def test_trim_argument(self):
         req = Request.from_values("/bubble?foo= 1 &bar=bees&n=22")
         parser = RequestParser()
-        parser.add_argument('foo')
+        parser.add_argument('foo', location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ' 1 ')
 
         parser = RequestParser()
-        parser.add_argument('foo', trim=True)
+        parser.add_argument('foo', trim=True, location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], '1')
 
         parser = RequestParser()
-        parser.add_argument('foo', trim=True, type=int)
+        parser.add_argument('foo', trim=True, type=int, location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], 1)
 
     def test_trim_request_parser(self):
         req = Request.from_values("/bubble?foo= 1 &bar=bees&n=22")
         parser = RequestParser(trim=False)
-        parser.add_argument('foo')
+        parser.add_argument('foo', location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], ' 1 ')
 
         parser = RequestParser(trim=True)
-        parser.add_argument('foo')
+        parser.add_argument('foo', location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], '1')
 
         parser = RequestParser(trim=True)
-        parser.add_argument('foo', type=int)
+        parser.add_argument('foo', type=int, location="args")
         args = parser.parse_args(req)
         self.assertEqual(args['foo'], 1)
 
