diff options
| author | J08nY | 2017-06-27 22:16:08 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-27 22:16:08 +0200 |
| commit | 1802b0f6eaaa2cc09ef0941774239499e369dfb0 (patch) | |
| tree | cfb0c92735d7dd5dd04fc2f27a9151db1c296fd2 | |
| parent | 13f28275a6e109ad4b3548cb2d950b83fe7417ce (diff) | |
| download | mailman-pgp-1802b0f6eaaa2cc09ef0941774239499e369dfb0.tar.gz mailman-pgp-1802b0f6eaaa2cc09ef0941774239499e369dfb0.tar.zst mailman-pgp-1802b0f6eaaa2cc09ef0941774239499e369dfb0.zip | |
Add basic REST lists endpoint tests.
| -rw-r--r-- | src/mailman_pgp/rest/lists.py | 2 | ||||
| -rw-r--r-- | src/mailman_pgp/rest/tests/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman_pgp/rest/tests/test_lists.py | 48 |
3 files changed, 49 insertions, 1 deletions
diff --git a/src/mailman_pgp/rest/lists.py b/src/mailman_pgp/rest/lists.py index fc7bbef..4cffa38 100644 --- a/src/mailman_pgp/rest/lists.py +++ b/src/mailman_pgp/rest/lists.py @@ -63,7 +63,7 @@ class AnEncryptedList(_EncryptedBase): def on_get(self, request, response): """/lists/<list_id>""" if self._mlist is None: - return not_found() + return not_found(response) else: okay(response, self._resource_as_json(self._mlist)) diff --git a/src/mailman_pgp/rest/tests/__init__.py b/src/mailman_pgp/rest/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/mailman_pgp/rest/tests/__init__.py diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py new file mode 100644 index 0000000..3bdd01d --- /dev/null +++ b/src/mailman_pgp/rest/tests/test_lists.py @@ -0,0 +1,48 @@ +# Copyright (C) 2017 Jan Jancar +# +# This file is a part of the Mailman PGP plugin. +# +# This program 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. +# +# This program 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 +# this program. If not, see <http://www.gnu.org/licenses/>. + +from unittest import TestCase +from urllib.error import HTTPError + +from mailman.app.lifecycle import create_list +from mailman.database.transaction import transaction as mailman_transaction +from mailman.testing.helpers import call_api +from mailman.testing.layers import RESTLayer + + +class TestLists(TestCase): + layer = RESTLayer + + def setUp(self): + with mailman_transaction(): + self.mlist = create_list('test@example.com', + style_name='pgp-default') + + def test_missing_list(self): + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.1/plugins/pgp/lists/' + 'missing.example.com') + self.assertEqual(cm.exception.code, 404) + + def test_has_list(self): + json, response = call_api( + 'http://localhost:9001/3.1/plugins/pgp/lists/') + self.assertEqual(json['total_size'], 1) + self.assertEqual(len(json['entries']), 1) + lists = json['entries'] + plist = lists[0] + self.assertEqual(plist['list_id'], self.mlist.list_id) |
