Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 494f8f98 by Abhilash Raj at 2019-03-21T02:46:36Z Add support for falcon 2.0.0a1 Fix the version constraint for falcon. - We support falcon version>1.0.0, we don't need to pin versions greater than 1.4.0. - Fix tests and code to support all falcon versions. - - - - - de15b816 by Abhilash Raj at 2019-03-21T02:46:36Z Merge branch 'fix-falcon' into 'master' Add support for falcon 2.0.0a1 See merge request mailman/mailman!476 - - - - - 4 changed files: - setup.py - src/mailman/rest/helpers.py - src/mailman/rest/tests/test_wsgiapp.py - src/mailman/rest/wsgiapp.py Changes: ===================================== setup.py ===================================== @@ -109,7 +109,7 @@ case second `m'. Any other spelling is incorrect.""", 'atpublic', 'click>=7.0', 'dnspython>=1.14.0', - 'falcon>=1.4.0', + 'falcon>1.0.0', 'flufl.bounce', 'flufl.i18n>=2.0', 'flufl.lock>=3.1', ===================================== src/mailman/rest/helpers.py ===================================== @@ -144,11 +144,20 @@ class CollectionMixin: """ # Allow falcon's HTTPBadRequest exceptions to percolate up. They'll # get turned into HTTP 400 errors. - count = request.get_param_as_int('count', min=0) - page = request.get_param_as_int('page', min=1) + count = request.get_param_as_int('count') + page = request.get_param_as_int('page') total_size = len(collection) if count is None and page is None: return 0, total_size, collection + # TODO(maxking): Count and page should be positive integers. Once + # falcon 2.0.0 is out and we can jump to it, we can remove this logic + # and use `min_value` parameter in request.get_param_as_int. + if count < 0: + raise falcon.HTTPInvalidParam( + count, 'count should be a positive integer.') + if page < 1: + raise falcon.HTTPInvalidParam( + page, 'page should be greater than 0.') list_start = (page - 1) * count list_end = page * count return list_start, total_size, collection[list_start:list_end] @@ -347,6 +356,6 @@ def get_request_params(request): # JSONHandler handler to parse json media type, so we can just do # `request.media` to return the request params passed as json body. if request.content_type.startswith('application/json'): - return request.media + return request.media or dict() # request.params returns the parameters passed as URL form encoded. - return request.params + return request.params or dict() ===================================== src/mailman/rest/tests/test_wsgiapp.py ===================================== @@ -48,15 +48,15 @@ class TestSupportedContentType(unittest.TestCase): response = requests.post( url, headers={'Content-Type': 'application/json'}, + json=dict(), auth=basic_auth) self.assertEqual(response.status_code, 400) self.assertEqual(response.headers.get('content-type', None), 'application/json; charset=UTF-8') self.assertEqual( response.json(), - {'title': 'Invalid JSON', - 'description': 'Could not parse JSON body -' - ' Expecting value: line 1 column 1 (char 0)'} + {'title': '400 Bad Request', + 'description': 'Missing Parameter: mail_host'} ) # Now, let's try to send in json valid json but cause a missing # required parameter error. ===================================== src/mailman/rest/wsgiapp.py ===================================== @@ -113,7 +113,7 @@ class ObjectRouter: # We don't need this method for object-based routing. raise NotImplementedError - def find(self, uri): + def find(self, uri, req=None): segments = uri.split(SLASH) # Since the path is always rooted at /, skip the first segment, which # will always be the empty string. View it on GitLab: https://gitlab.com/mailman/mailman/compare/3a1d9a3d7c6b1fae8f9e27b8181ea3e1d7c863b2...de15b8167245a71797d694990d3053472e25e150 -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/3a1d9a3d7c6b1fae8f9e27b8181ea3e1d7c863b2...de15b8167245a71797d694990d3053472e25e150 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org