127
126
def test_single_message(self):
128
127
conn, archive = self.makeArchive()
129
128
self.makeMessages(conn, archive, 1)
131
# We get a single message when we ask for it.
132
messages = conn.get_messages(archive, 'date', 1, '')[1]
133
self.assertMessages([0], messages)
136
# The raw message matches what we generated, and the result is
137
# formatted according to the default settings.
138
expected_raw = TEMPLATE_MESSAGE.format(
139
date=formatdate(0), id='<message0@example.com>')
140
self.assertEqual(expected_raw, messages[0]['raw'])
141
pmsg = _parse_message(expected_raw)[1]
142
pmsg['raw'] = expected_raw
146
headers=['date', 'from', 'subject', 'message-id'],
130
[0], conn.get_messages(archive, 'date', 1, '')[1])
150
132
def test_limit(self):
151
133
conn, archive = self.makeArchive()
180
162
self.assertMessages([0, 1], messages)
181
163
prev, messages, next = conn.get_messages(archive, 'date', 2, next)
182
164
self.assertMessages([2, 3], messages)
183
prev, messages, next = conn.get_messages(
184
archive, 'date', 2, prev, backward=True)
185
self.assertMessages([0, 1], messages)
186
prev, messages, next = conn.get_messages(
187
archive, 'date', 2, prev, backward=True)
188
self.assertIs(None, prev)
189
self.assertMessages([], messages)
190
self.assertIs(None, next)
192
def test_date_filter(self):
193
conn, archive = self.makeArchive()
194
self.makeMessages(conn, archive, 10)
195
start = datetime.datetime.utcfromtimestamp(250).replace(
197
finish = datetime.datetime.utcfromtimestamp(500).replace(
199
prev, messages, next = conn.get_messages(
200
archive, 'date', 2, '', start_date=start, finish_date=finish)
201
self.assertMessages([3, 4], messages)
202
prev, messages, next = conn.get_messages(
203
archive, 'date', 2, next, start_date=start, finish_date=finish)
204
self.assertMessages([5], messages)
207
class TestMessageFormatter(unittest.TestCase):
210
parsed = _parse_message(TEST_MESSAGE)[1]
211
parsed['raw'] = TEST_MESSAGE
212
formatted = _format_message(
214
headers=['date', 'from', 'subject', 'message-id'],
218
'date': '2000-01-01T11:02:34+11:00',
219
'from': 'sysadmin@example.com',
220
'message-id': '<aaaaaaaaaaaaa@example.com>',
221
'subject': 'Everything is broken',
225
self.assertEqual(expected, formatted)
165
# XXX: We shouldn't have to reverse the sort order. There should
166
# be a flag to work backwards, but I'm not sure if we can get
167
# that from Cassandra without reversing in Python.
168
prev, messages, next = conn.get_messages(archive, '-date', 2, prev)
169
self.assertMessages([1, 0], messages)