summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2014-11-02 15:29:10 -0500
committerBarry Warsaw2014-11-02 15:29:10 -0500
commit9b19d1a9d77e71afc0783f22496bd623eda3024b (patch)
tree0f6942efb5f23ca54695769ee240119ad5a75ceb /src
parentdfc451f81ccc8b0947fb3fa42e94c55026984cf8 (diff)
downloadmailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.tar.gz
mailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.tar.zst
mailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/rest/docs/helpers.rst30
-rw-r--r--src/mailman/rest/tests/test_paginate.py10
2 files changed, 23 insertions, 17 deletions
diff --git a/src/mailman/rest/docs/helpers.rst b/src/mailman/rest/docs/helpers.rst
index 1a2a244ac..68dfda1be 100644
--- a/src/mailman/rest/docs/helpers.rst
+++ b/src/mailman/rest/docs/helpers.rst
@@ -73,7 +73,7 @@ converting their values.
>>> validator = Validator(one=int, two=unicode, three=bool)
>>> class FakeRequest:
- ... params = {}
+ ... params = None
>>> FakeRequest.params = dict(one='1', two='two', three='yes')
On valid input, the validator can be used as a ``**keyword`` argument.
@@ -157,12 +157,17 @@ such form data. Specifically, when a key shows up multiple times in the form
data, a list is given to the validator.
::
- # Of course we can't use a normal dictionary, but webob has a useful data
- # type we can use.
- >>> from webob.multidict import MultiDict
- >>> form_data = MultiDict(one='1', many='3')
- >>> form_data.add('many', '4')
- >>> form_data.add('many', '5')
+ # We can't use a normal dictionary because we'll have multiple keys, but
+ # the validator only wants to call .items() on the object.
+ >>> class MultiDict:
+ ... def __init__(self, *params): self.values = list(params)
+ ... def items(self): return iter(self.values)
+ >>> form_data = MultiDict(
+ ... ('one', '1'),
+ ... ('many', '3'),
+ ... ('many', '4'),
+ ... ('many', '5'),
+ ... )
This is a validation function that ensures the value is a list.
@@ -191,11 +196,12 @@ And a validator to pull it all together.
The list values are guaranteed to be in the same order they show up in the
form data.
- >>> from webob.multidict import MultiDict
- >>> form_data = MultiDict(one='1', many='3')
- >>> form_data.add('many', '5')
- >>> form_data.add('many', '4')
- >>> FakeRequest.params = form_data
+ >>> FakeRequest.params = MultiDict(
+ ... ('one', '1'),
+ ... ('many', '3'),
+ ... ('many', '5'),
+ ... ('many', '4'),
+ ... )
>>> values = validator(FakeRequest)
>>> print(values['one'])
1
diff --git a/src/mailman/rest/tests/test_paginate.py b/src/mailman/rest/tests/test_paginate.py
index a710307ca..e267100c7 100644
--- a/src/mailman/rest/tests/test_paginate.py
+++ b/src/mailman/rest/tests/test_paginate.py
@@ -27,7 +27,7 @@ __all__ = [
import unittest
-from falcon import InvalidParam, Request
+from falcon import HTTPInvalidParam, Request
from mailman.app.lifecycle import create_list
from mailman.database.transaction import transaction
from mailman.rest.helpers import paginate
@@ -104,7 +104,7 @@ class TestPaginateHelper(unittest.TestCase):
@paginate
def get_collection(self, request):
return []
- self.assertRaises(InvalidParam, get_collection,
+ self.assertRaises(HTTPInvalidParam, get_collection,
None, _FakeRequest('two', 1))
def test_negative_count(self):
@@ -112,7 +112,7 @@ class TestPaginateHelper(unittest.TestCase):
@paginate
def get_collection(self, request):
return ['one', 'two', 'three', 'four', 'five']
- self.assertRaises(InvalidParam, get_collection,
+ self.assertRaises(HTTPInvalidParam, get_collection,
None, _FakeRequest(-1, 1))
def test_negative_page(self):
@@ -120,7 +120,7 @@ class TestPaginateHelper(unittest.TestCase):
@paginate
def get_collection(self, request):
return ['one', 'two', 'three', 'four', 'five']
- self.assertRaises(InvalidParam, get_collection,
+ self.assertRaises(HTTPInvalidParam, get_collection,
None, _FakeRequest(1, -1))
def test_negative_page_and_count(self):
@@ -128,5 +128,5 @@ class TestPaginateHelper(unittest.TestCase):
@paginate
def get_collection(self, request):
return ['one', 'two', 'three', 'four', 'five']
- self.assertRaises(InvalidParam, get_collection,
+ self.assertRaises(HTTPInvalidParam, get_collection,
None, _FakeRequest(-1, -1))