~barry/mailman/lp1423756

« back to all changes in this revision

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

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2014 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 message store."""
 
19
 
 
20
__all__ = [
 
21
    'TestMessageStore',
 
22
    ]
 
23
 
 
24
 
 
25
import unittest
 
26
 
 
27
from mailman.interfaces.messages import IMessageStore
 
28
from mailman.testing.helpers import (
 
29
    specialized_message_from_string as mfs)
 
30
from mailman.testing.layers import ConfigLayer
 
31
from mailman.utilities.email import add_message_hash
 
32
from zope.component import getUtility
 
33
 
 
34
 
 
35
 
 
36
class TestMessageStore(unittest.TestCase):
 
37
    layer = ConfigLayer
 
38
 
 
39
    def setUp(self):
 
40
        self._store = getUtility(IMessageStore)
 
41
 
 
42
    def test_message_id_required(self):
 
43
        # The Message-ID header is required in order to add it to the store.
 
44
        message = mfs("""\
 
45
Subject: An important message
 
46
 
 
47
This message is very important.
 
48
""")
 
49
        self.assertRaises(ValueError, self._store.add, message)
 
50
 
 
51
    def test_get_message_by_hash(self):
 
52
        # Messages have an X-Message-ID-Hash header, the value of which can be
 
53
        # used to look the message up in the message store.
 
54
        message = mfs("""\
 
55
Subject: An important message
 
56
Message-ID: <ant>
 
57
 
 
58
This message is very important.
 
59
""")
 
60
        add_message_hash(message)
 
61
        self._store.add(message)
 
62
        self.assertEqual(message['x-message-id-hash'],
 
63
                         'V3YEHAFKE2WVJNK63Z7RFP4JMHISI2RG')
 
64
        found = self._store.get_message_by_hash(
 
65
            'V3YEHAFKE2WVJNK63Z7RFP4JMHISI2RG')
 
66
        self.assertEqual(found['message-id'], '<ant>')
 
67
        self.assertEqual(found['x-message-id-hash'],
 
68
                         'V3YEHAFKE2WVJNK63Z7RFP4JMHISI2RG')
 
69
 
 
70
    def test_cannot_delete_missing_message(self):
 
71
        self.assertRaises(LookupError, self._store.delete_message, 'missing')