1
# Copyright (C) 2014 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
"""Test the message store."""
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
36
class TestMessageStore(unittest.TestCase):
40
self._store = getUtility(IMessageStore)
42
def test_message_id_required(self):
43
# The Message-ID header is required in order to add it to the store.
45
Subject: An important message
47
This message is very important.
49
self.assertRaises(ValueError, self._store.add, message)
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.
55
Subject: An important message
58
This message is very important.
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')
70
def test_cannot_delete_missing_message(self):
71
self.assertRaises(LookupError, self._store.delete_message, 'missing')