From a6fcb3e732fbf880e02a94ce8265be6624459ed8 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 1 Sep 2011 20:04:06 -0400 Subject: * Getting the roster or configuration of a nonexistent list did not give a 404 error (LP: #837676). Given by Stephen A. Goss. --- src/mailman/docs/NEWS.rst | 2 + src/mailman/rest/lists.py | 4 ++ src/mailman/rest/tests/test_lists.py | 89 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/mailman/rest/tests/test_lists.py diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 597387b40..2a59835d6 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -49,6 +49,8 @@ REST * DELETE users via the REST API. (LP: #820660) * Moderators and owners can be added via REST (LP: #834130). Given by Stephen A. Goss. + * Getting the roster or configuration of a nonexistent list did not give a + 404 error (LP: #837676). Given by Stephen A. Goss. Commands -------- diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index 6a6388320..32aa607b6 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -155,11 +155,15 @@ class AList(_ListBase): @resource.child(roster_matcher) def roster(self, request, segments, role): """Return the collection of all a mailing list's members.""" + if self._mlist is None: + return http.not_found() return MembersOfList(self._mlist, role) @resource.child(config_matcher) def config(self, request, segments, attribute=None): """Return a mailing list configuration object.""" + if self._mlist is None: + return http.not_found() return ListConfiguration(self._mlist, attribute) diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py new file mode 100644 index 000000000..fe8519404 --- /dev/null +++ b/src/mailman/rest/tests/test_lists.py @@ -0,0 +1,89 @@ +# Copyright (C) 2011 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see . + +"""REST list tests.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'test_suite', + ] + + +import unittest + +from urllib2 import HTTPError + +from mailman.testing.helpers import call_api +from mailman.testing.layers import RESTLayer + + + +class TestLists(unittest.TestCase): + layer = RESTLayer + + def test_missing_list_roster_member_404(self): + # /lists//roster/member gives 404 + try: + # For Python 2.6. + call_api('http://localhost:9001/3.0/lists/missing@example.com' + '/roster/member') + except HTTPError as exc: + self.assertEqual(exc.code, 404) + else: + raise AssertionError('Expected HTTPError') + + def test_missing_list_roster_owner_404(self): + # /lists//roster/owner gives 404 + try: + # For Python 2.6. + call_api('http://localhost:9001/3.0/lists/missing@example.com' + '/roster/owner') + except HTTPError as exc: + self.assertEqual(exc.code, 404) + else: + raise AssertionError('Expected HTTPError') + + def test_missing_list_roster_moderator_404(self): + # /lists//roster/member gives 404 + try: + # For Python 2.6. + call_api('http://localhost:9001/3.0/lists/missing@example.com' + '/roster/moderator') + except HTTPError as exc: + self.assertEqual(exc.code, 404) + else: + raise AssertionError('Expected HTTPError') + + def test_missing_list_configuration_404(self): + # /lists//config gives 404 + try: + # For Python 2.6. + call_api( + 'http://localhost:9001/3.0/lists/missing@example.com/config') + except HTTPError as exc: + self.assertEqual(exc.code, 404) + else: + raise AssertionError('Expected HTTPError') + + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestLists)) + return suite -- cgit v1.2.3-70-g09d2