1
# Copyright (C) 2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""REST moderation tests."""
20
from __future__ import absolute_import, print_function, unicode_literals
29
from urllib2 import HTTPError
31
from mailman.app.lifecycle import create_list
32
from mailman.app.moderator import hold_message, hold_subscription
33
from mailman.config import config
34
from mailman.interfaces.member import DeliveryMode
35
from mailman.testing.helpers import (
36
call_api, specialized_message_from_string as mfs)
37
from mailman.testing.layers import RESTLayer
41
class TestModeration(unittest.TestCase):
45
self._mlist = create_list('ant@example.com')
47
From: anne@example.com
56
def test_not_found(self):
57
# When a bogus mailing list is given, 404 should result.
60
call_api('http://localhost:9001/3.0/lists/bee@example.com/held')
61
except HTTPError as exc:
62
self.assertEqual(exc.code, 404)
64
raise AssertionError('Expected HTTPError')
66
def test_bad_request_id(self):
67
# Bad request when request_id is not an integer.
71
'http://localhost:9001/3.0/lists/ant@example.com/held/bogus')
72
except HTTPError as exc:
73
self.assertEqual(exc.code, 400)
75
raise AssertionError('Expected HTTPError')
77
def test_subscription_request_as_held_message(self):
78
# Provide the request id of a subscription request using the held
79
# message API returns a not-found even though the request id is
81
held_id = hold_message(self._mlist, self._msg)
82
subscribe_id = hold_subscription(
83
self._mlist, 'bperson@example.net', 'Bart Person', 'xyz',
84
DeliveryMode.regular, 'en')
85
config.db.store.commit()
86
url = 'http://localhost:9001/3.0/lists/ant@example.com/held/{0}'
88
call_api(url.format(subscribe_id))
89
except HTTPError as exc:
90
self.assertEqual(exc.code, 404)
92
raise AssertionError('Expected HTTPError')
93
# But using the held_id returns a valid response.
94
response, content = call_api(url.format(held_id))
95
self.assertEqual(response['key'], '<alpha>')
97
def test_bad_action(self):
98
# POSTing to a held message with a bad action.
99
held_id = hold_message(self._mlist, self._msg)
100
url = 'http://localhost:9001/3.0/lists/ant@example.com/held/{0}'
102
call_api(url.format(held_id), {'action': 'bogus'})
103
except HTTPError as exc:
104
self.assertEqual(exc.code, 400)
105
self.assertEqual(exc.msg, 'Cannot convert parameters: action')
107
raise AssertionError('Expected HTTPError')