~barry/mailman/work1

« back to all changes in this revision

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

  • Committer: Barry Warsaw
  • Date: 2013-03-11 19:24:48 UTC
  • mfrom: (7178.2.26 3.0)
  • Revision ID: barry@list.org-20130311192448-gb1h8ca77weapdkx
trunk merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2012 by the Free Software Foundation, Inc.
 
1
# Copyright (C) 2012-2013 by the Free Software Foundation, Inc.
2
2
#
3
3
# This file is part of GNU Mailman.
4
4
#
21
21
 
22
22
__metaclass__ = type
23
23
__all__ = [
 
24
    'TestRequests',
24
25
    ]
25
26
 
26
27
 
39
40
 
40
41
    def setUp(self):
41
42
        self._mlist = create_list('ant@example.com')
 
43
        self._requests_db = IListRequests(self._mlist)
42
44
        self._msg = mfs("""\
43
45
From: anne@example.com
44
46
To: ant@example.com
51
53
    def test_get_request_with_type(self):
52
54
        # get_request() takes an optional request type.
53
55
        request_id = hold_message(self._mlist, self._msg)
54
 
        requests_db = IListRequests(self._mlist)
55
56
        # Submit a request with a non-matching type.  This should return None
56
57
        # as if there were no matches.
57
 
        response = requests_db.get_request(
 
58
        response = self._requests_db.get_request(
58
59
            request_id, RequestType.subscription)
59
60
        self.assertEqual(response, None)
60
61
        # Submit the same request with a matching type.
61
 
        key, data = requests_db.get_request(
 
62
        key, data = self._requests_db.get_request(
62
63
            request_id, RequestType.held_message)
63
64
        self.assertEqual(key, '<alpha>')
64
65
        # It should also succeed with no optional request type given.
65
 
        key, data = requests_db.get_request(request_id)
 
66
        key, data = self._requests_db.get_request(request_id)
66
67
        self.assertEqual(key, '<alpha>')
 
68
 
 
69
    def test_hold_with_bogus_type(self):
 
70
        # Calling hold_request() with a bogus request type is an error.
 
71
        with self.assertRaises(TypeError) as cm:
 
72
            self._requests_db.hold_request(5, 'foo')
 
73
        self.assertEqual(cm.exception.message, 5)
 
74
 
 
75
    def test_delete_missing_request(self):
 
76
        # Trying to delete a missing request is an error.
 
77
        with self.assertRaises(KeyError) as cm:
 
78
            self._requests_db.delete_request(801)
 
79
        self.assertEqual(cm.exception.message, 801)