127
129
def test_single_message(self):
128
130
conn, archive = self.makeArchive()
129
131
self.makeMessages(conn, archive, 1)
133
# We get a single message when we ask for it.
130
134
messages = conn.get_messages(archive, 'date', 1, '')[1]
131
135
self.assertMessages([0], messages)
132
136
cmsg = messages[0]
138
# The content matches what we generated, and the result is
139
# formatted according to the default settings.
133
140
expected_content = TEMPLATE_MESSAGE.format(
134
141
date=formatdate(0), id='<message0@example.com>')
135
142
self.assertEqual(expected_content, messages[0]['content'])
136
143
pmsg = _parse_message(expected_content)[1]
137
self.assertEqual(pmsg['date'], cmsg['date'])
138
self.assertEqual(pmsg['from'], cmsg['from'])
139
self.assertEqual(pmsg['subject'], cmsg['subject'])
140
self.assertEqual(pmsg['message-id'], cmsg['message-id'])
144
pmsg['content'] = expected_content
147
['date', 'from', 'subject', 'message-id', 'content'],
142
151
def test_limit(self):
143
152
conn, archive = self.makeArchive()
194
203
prev, messages, next = conn.get_messages(
195
204
archive, 'date', 2, next, start_date=start, finish_date=finish)
196
205
self.assertMessages([5], messages)
208
class TestMessageFormatters(unittest.TestCase):
211
parsed = _parse_message(TEST_MESSAGE)[1]
212
parsed['content'] = TEST_MESSAGE
213
want, func = FORMATS['all'](['date', 'from', 'subject', 'message-id'])
215
['content', 'date', 'from', 'message-id', 'subject'],
217
formatted = func(parsed)
219
'date': '2000-01-01T11:02:34+11:00',
220
'from': 'sysadmin@example.com',
221
'message-id': '<aaaaaaaaaaaaa@example.com>',
222
'subject': 'Everything is broken',
223
'content': TEST_MESSAGE,
225
self.assertEqual(expected, formatted)