97
98
parsed_message = _parse_message(TEST_MESSAGE)[1]
98
99
for key, value in parsed_message.iteritems():
99
100
self.assertEqual(value, cmsg[key])
103
class TestGetMessages(unittest.TestCase):
105
def assertMessages(self, expected_ids, messages):
107
'<message%d@example.com>' % id for id in expected_ids]
108
actual_msgids = [msg['message-id'] for msg in messages]
109
self.assertEqual(expected_msgids, actual_msgids)
111
def makeMessages(self, conn, archive, count):
115
TEMPLATE_MESSAGE.format(
116
date=formatdate(i * 100),
117
id='<message%d@example.com>' % i))
118
for i in range(count)]
120
def makeArchive(self):
121
conn = CassandraConnection(
122
os.environ['GRACKLE_TEST_KEYSPACE'], ['localhost:9160'])
123
archive = next(_RandomNameSequence())
126
def test_single_message(self):
127
conn, archive = self.makeArchive()
128
self.makeMessages(conn, archive, 1)
130
[0], conn.get_messages(archive, 'date', 1, '')[0])
132
def test_limit(self):
133
conn, archive = self.makeArchive()
134
self.makeMessages(conn, archive, 4)
136
[0, 1], conn.get_messages(archive, 'date', 2, '')[0])
138
def test_order(self):
139
conn, archive = self.makeArchive()
140
self.makeMessages(conn, archive, 4)
142
[3, 2], conn.get_messages(archive, '-date', 2, '')[0])
144
def test_batching_forward(self):
145
conn, archive = self.makeArchive()
146
self.makeMessages(conn, archive, 5)
147
messages, start = conn.get_messages(archive, 'date', 2, '')
148
self.assertMessages([0, 1], messages)
149
messages, start = conn.get_messages(archive, 'date', 2, start)
150
self.assertMessages([2, 3], messages)
151
messages, start = conn.get_messages(archive, 'date', 2, start)
152
self.assertMessages([4], messages)
153
self.assertIs(None, start)