Barry Warsaw pushed to branch release-3.0 at mailman / Mailman
Commits: 9281b387 by Barry Warsaw at 2015-12-12T20:27:30Z _resource_as_dict() may not return None. Add some assertions to prove this is always the case. - - - - - 4 changed files: - src/mailman/rest/helpers.py - src/mailman/rest/post_moderation.py - src/mailman/rest/sub_moderation.py - src/mailman/rest/tests/test_moderation.py Changes: ===================================== src/mailman/rest/helpers.py ===================================== --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -132,7 +132,9 @@ class CollectionMixin: def _resource_as_json(self, resource): """Return the JSON formatted representation of the resource.""" - return etag(self._resource_as_dict(resource)) + resource = self._resource_as_dict(resource) + assert resource is not None, resource + return etag(resource) def _get_collection(self, request): """Return the collection as a concrete list. @@ -173,6 +175,7 @@ class CollectionMixin: if len(collection) != 0: entries = [self._resource_as_dict(resource) for resource in collection] + assert None not in entries, entries # Tag the resources but use the dictionaries. [etag(resource) for resource in entries] # Create the collection resource ===================================== src/mailman/rest/post_moderation.py ===================================== --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -138,7 +138,9 @@ class HeldMessages(_HeldMessageBase, CollectionMixin): def _resource_as_dict(self, request): """See `CollectionMixin`.""" - return self._make_resource(request.id) + resource = self._make_resource(request.id) + assert resource is not None, resource + return resource def _get_collection(self, request): requests = IListRequests(self._mlist) ===================================== src/mailman/rest/sub_moderation.py ===================================== --- a/src/mailman/rest/sub_moderation.py +++ b/src/mailman/rest/sub_moderation.py @@ -65,6 +65,7 @@ class IndividualRequest(_ModerationBase): # the pending table. try: resource = self._resource_as_dict(self._token) + assert resource is not None, resource except LookupError: not_found(response) return ===================================== src/mailman/rest/tests/test_moderation.py ===================================== --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -69,7 +69,7 @@ Something else. self.assertEqual(cm.exception.code, 400) def test_missing_held_message_request_id(self): - # Bad request when the request_id is not in the database. + # Not found when the request_id is not in the database. with self.assertRaises(HTTPError) as cm: call_api('http://localhost:9001/3.0/lists/a...@example.com/held/99') self.assertEqual(cm.exception.code, 404) View it on GitLab: https://gitlab.com/mailman/mailman/commit/9281b3871f5e194343cd4c4ec75b9c209e71926f
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org