56
56
def start_server(self):
57
57
service = HTTPServer(('', self.port), FakeGrackleRequestHandler)
58
58
service.messages = self.messages
59
for archive_id, messages in service.messages.iteritems():
60
for message in messages:
61
message.setdefault('headers', {})
60
63
service.serve_forever()
134
137
messages = messages[start:end]
139
for message in messages:
140
message = dict(message)
141
if 'headers' in parameters:
143
(k, v) for k, v in message['headers'].iteritems()
144
if k in parameters['headers'])
145
message['headers'] = headers
146
new_messages.append(message)
136
'messages': messages,
148
'messages': new_messages,
137
149
'next_memo': next_memo,
138
150
'previous_memo': previous_memo
272
284
{'message_id': 'bar', 'date': '2011-03-24'}]}):
273
285
with ExpectedException(UnsupportedOrder):
274
286
client.get_messages('baz', order='nonsense')
288
def test_get_messages_headers_no_headers(self):
289
client = GrackleClient('localhost', 8440)
290
with fake_grackle_service(client,
292
{'message_id': 'foo'}
294
response = client.get_messages('baz', headers=[
295
'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
296
first_message = response['messages'][0]
297
self.assertEqual('foo', first_message['message_id'])
298
self.assertEqual({}, first_message['headers'])
300
def test_get_messages_headers_exclude_headers(self):
301
client = GrackleClient('localhost', 8440)
302
with fake_grackle_service(client,
304
{'message_id': 'foo', 'headers': {'From': 'me'}}
306
response = client.get_messages('baz', headers=[
307
'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
308
first_message = response['messages'][0]
309
self.assertEqual('foo', first_message['message_id'])
310
self.assertEqual({}, first_message['headers'])
312
def test_get_messages_headers_include_headers(self):
313
client = GrackleClient('localhost', 8440)
314
with fake_grackle_service(client,
316
{'message_id': 'foo', 'headers': {'From': 'me', 'To': 'you'}}
318
response = client.get_messages('baz', headers=[
320
first_message = response['messages'][0]
321
self.assertEqual('foo', first_message['message_id'])
322
self.assertEqual({'From': 'me', 'To': 'you'}, first_message['headers'])