Skip to content

Commit

Permalink
Merge pull request flask-restful#41 from frankstratton/master
Browse files Browse the repository at this point in the history
action='append' should always return a list
  • Loading branch information
kyleconroy committed Jan 23, 2013
2 parents c2d78f8 + 89febd6 commit 9fea45d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions flask_restful/reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def parse(self, request):
if not results:
return self.default

if self.action == 'append':
return results

if self.action == 'store' or len(results) == 1:
return results[0]
return results
Expand Down
11 changes: 10 additions & 1 deletion tests/test_reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ def test_parse_append(self):
args = parser.parse_args(req)
self.assertEquals(args['foo'], ["bar", "bat"])

def test_parse_append_single(self):
req = Request.from_values("/bubble?foo=bar")

parser = RequestParser()
parser.add_argument("foo", action="append"),

args = parser.parse_args(req)
self.assertEquals(args['foo'], ["bar"])


def test_parse_dest(self):
req = Request.from_values("/bubble?foo=bar")
Expand Down Expand Up @@ -300,7 +309,7 @@ def test_parse_lte_gte_append(self):
parser.add_argument("foo", operators=["<=", "="], action="append")

args = parser.parse_args(Request.from_values("/bubble?foo<=bar"))
self.assertEquals(args['foo'], "bar")
self.assertEquals(args['foo'], ["bar"])


def test_parse_lte_gte_missing(self):
Expand Down

0 comments on commit 9fea45d

Please sign in to comment.