diff options
| author | Barry Warsaw | 2016-01-03 21:59:35 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2016-01-03 21:59:35 -0500 |
| commit | ff31bf58804fc984c694f6acfaa302042bc85d89 (patch) | |
| tree | 5bc6a153bd0604364b931c8c0c70c10faea002c9 /src/mailman | |
| parent | f390e08c31477c476e1312d03771b68e22b42675 (diff) | |
| download | mailman-ff31bf58804fc984c694f6acfaa302042bc85d89.tar.gz mailman-ff31bf58804fc984c694f6acfaa302042bc85d89.tar.zst mailman-ff31bf58804fc984c694f6acfaa302042bc85d89.zip | |
Diffstat (limited to 'src/mailman')
| -rw-r--r-- | src/mailman/app/commands.py | 2 | ||||
| -rw-r--r-- | src/mailman/chains/base.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/helpers.py | 6 | ||||
| -rw-r--r-- | src/mailman/rest/members.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_helpers.py | 82 | ||||
| -rw-r--r-- | src/mailman/utilities/uid.py | 4 |
6 files changed, 90 insertions, 8 deletions
diff --git a/src/mailman/app/commands.py b/src/mailman/app/commands.py index 45afe230e..35158da2a 100644 --- a/src/mailman/app/commands.py +++ b/src/mailman/app/commands.py @@ -35,6 +35,6 @@ def initialize(): command = command_class() verifyObject(IEmailCommand, command) assert command_class.name not in config.commands, ( - 'Duplicate email command "{0}" found in {1}'.format( + 'Duplicate email command "{}" found in {}'.format( command_class.name, command_class.__module__)) config.commands[command_class.name] = command_class() diff --git a/src/mailman/chains/base.py b/src/mailman/chains/base.py index 911703ae9..a2266cf38 100644 --- a/src/mailman/chains/base.py +++ b/src/mailman/chains/base.py @@ -71,7 +71,7 @@ class TerminalChainBase: :param msg: The message. :param msgdata: The message metadata. """ - raise NotImplementedError # pragma: no cover + raise NotImplementedError def get_links(self, mlist, msg, msgdata): """See `IChain`.""" diff --git a/src/mailman/rest/helpers.py b/src/mailman/rest/helpers.py index be5a4804b..8de2632bc 100644 --- a/src/mailman/rest/helpers.py +++ b/src/mailman/rest/helpers.py @@ -86,7 +86,7 @@ class ExtendedEncoder(json.JSONEncoder): # It's up to the decoding validator to associate this name with # the right Enum class. return obj.name - return json.JSONEncoder.default(self, obj) + return super().default(obj) def etag(resource): @@ -130,7 +130,7 @@ class CollectionMixin: :return: The representation of the resource. :rtype: dict """ - raise NotImplementedError # pragma: no cover + raise NotImplementedError def _resource_as_json(self, resource): """Return the JSON formatted representation of the resource.""" @@ -147,7 +147,7 @@ class CollectionMixin: :return: The collection :rtype: list """ - raise NotImplementedError # pragma: no cover + raise NotImplementedError def _paginate(self, request, collection): """Method to paginate through collection result lists. diff --git a/src/mailman/rest/members.py b/src/mailman/rest/members.py index 791a24656..3b69042da 100644 --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -100,7 +100,7 @@ class MemberCollection(_MemberBase): """ def _get_collection(self, request): """See `CollectionMixin`.""" - raise NotImplementedError # pragma: no cover + raise NotImplementedError def on_get(self, request, response): """roster/[members|owners|moderators]""" diff --git a/src/mailman/rest/tests/test_helpers.py b/src/mailman/rest/tests/test_helpers.py new file mode 100644 index 000000000..cab1f06fa --- /dev/null +++ b/src/mailman/rest/tests/test_helpers.py @@ -0,0 +1,82 @@ +# Copyright (C) 2016 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 <http://www.gnu.org/licenses/>. + +"""Additional tests for helpers.""" + +__all__ = [ + 'TestHelpers', + ] + + +import unittest + +from datetime import timedelta +from mailman.rest import helpers +from mailman.testing.layers import ConfigLayer + + +class FakeResponse: + def __init__(self): + self.body = 'not set' + + +class Unserializable: + pass + + + +class TestHelpers(unittest.TestCase): + layer = ConfigLayer + + def test_not_found_body_is_none(self): + response = FakeResponse() + helpers.not_found(response, body=None) + self.assertEqual(response.body, 'not set') + + def test_accepted_body_is_not_none(self): + response = FakeResponse() + helpers.accepted(response, body='set') + self.assertEqual(response.body, 'set') + + def test_bad_request_body_is_none(self): + response = FakeResponse() + helpers.bad_request(response, body=None) + self.assertEqual(response.body, 'not set') + + def test_conflict_body_is_none(self): + response = FakeResponse() + helpers.conflict(response, body=None) + self.assertEqual(response.body, 'not set') + + def test_forbidden_body_is_none(self): + response = FakeResponse() + helpers.forbidden(response, body=None) + self.assertEqual(response.body, 'not set') + + def test_json_encoding_datetime_seconds(self): + resource = dict(interval=timedelta(seconds=2)) + unjson = eval(helpers.etag(resource)) + self.assertEqual(unjson['interval'], '0d2.0s') + + def test_json_encoding_datetime_microseconds(self): + resource = dict(interval=timedelta(microseconds=2)) + unjson = eval(helpers.etag(resource)) + self.assertEqual(unjson['interval'], '0d2e-06s') + + def test_json_encoding_default(self): + resource = dict(interval=Unserializable()) + self.assertRaises(TypeError, helpers.etag, resource) diff --git a/src/mailman/utilities/uid.py b/src/mailman/utilities/uid.py index d2747df9d..e49b3d8dd 100644 --- a/src/mailman/utilities/uid.py +++ b/src/mailman/utilities/uid.py @@ -89,7 +89,7 @@ class _PredictableIDGenerator: The type of the returned id is intended to be the type that makes sense for the subclass overriding this method. """ - raise NotImplementedError # pragma: no cover + raise NotImplementedError def _next_predictable_id(self): """Generate a predictable id for when Mailman being tested. @@ -97,7 +97,7 @@ class _PredictableIDGenerator: The type of the returned id is intended to be the type that makes sense for the subclass overriding this method. """ - raise NotImplementedError # pragma: no cover + raise NotImplementedError def _next_id(self): with self._lock: |
