~stephen-xemacs/mailman/sprint-2012-overview

« back to all changes in this revision

Viewing changes to src/mailman/model/tests/test_requests.py

  • Committer: Barry Warsaw
  • Date: 2012-01-30 15:37:16 UTC
  • Revision ID: barry@list.org-20120130153716-s9qx07i6i0rltyax
 * Held messages can now be moderated through the REST API.  Mailing list
   resources now accept a `held` path component.  GETing this returns all held
   messages for the mailing list.  POSTing to a specific request id under this
   url can dispose of the message using `Action` enums.
 * `IRequests` interface is removed.  Now just use adaptation from
   `IListRequests` directly (which takes an `IMailingList` object).
 * `handle_message()` now allows for `Action.hold` which is synonymous with
   `Action.defer` (since the message is already being held).
 * `IListRequests.get_request()` now takes an optional `request_type`
   argument to narrow the search for the given request.

- also, print_function is now a standard __future__ import.  The template has
  been updated, but add this to modules as you edit them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2012 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
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)
 
8
# any later version.
 
9
#
 
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
 
13
# more details.
 
14
#
 
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/>.
 
17
 
 
18
"""Test the various pending requests interfaces."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    ]
 
25
 
 
26
 
 
27
import unittest
 
28
 
 
29
from mailman.app.lifecycle import create_list
 
30
from mailman.app.moderator import hold_message
 
31
from mailman.interfaces.requests import IListRequests, RequestType
 
32
from mailman.testing.helpers import specialized_message_from_string as mfs
 
33
from mailman.testing.layers import ConfigLayer
 
34
 
 
35
 
 
36
 
 
37
class TestRequests(unittest.TestCase):
 
38
    layer = ConfigLayer
 
39
 
 
40
    def setUp(self):
 
41
        self._mlist = create_list('ant@example.com')
 
42
        self._msg = mfs("""\
 
43
From: anne@example.com
 
44
To: ant@example.com
 
45
Subject: Something
 
46
Message-ID: <alpha>
 
47
 
 
48
Something else.
 
49
""")
 
50
 
 
51
    def test_get_request_with_type(self):
 
52
        # get_request() takes an optional request type.
 
53
        request_id = hold_message(self._mlist, self._msg)
 
54
        requests_db = IListRequests(self._mlist)
 
55
        # Submit a request with a non-matching type.  This should return None
 
56
        # as if there were no matches.
 
57
        response = requests_db.get_request(
 
58
            request_id, RequestType.subscription)
 
59
        self.assertEqual(response, None)
 
60
        # Submit the same request with a matching type.
 
61
        key, data = requests_db.get_request(
 
62
            request_id, RequestType.held_message)
 
63
        self.assertEqual(key, '<alpha>')
 
64
        # It should also succeed with no optional request type given.
 
65
        key, data = requests_db.get_request(request_id)
 
66
        self.assertEqual(key, '<alpha>')