Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
4eaed33f by Barry Warsaw at 2015-12-12T20:26:09Z
_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
@@ -134,7 +134,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.
@@ -175,6 +177,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
@@ -142,7 +142,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/[email protected]/held/99')
self.assertEqual(cm.exception.code, 404)
View it on GitLab:
https://gitlab.com/mailman/mailman/commit/4eaed33f2e7ddab482dbca7d8e945455b73dfb46
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org