28
def make_message(message_id, body='body text', headers=None, hidden=False):
28
def make_message(message_id, body='body', headers=None, hidden=False):
29
29
if headers is None:
31
31
headers['Message-Id'] = message_id
35
35
'thread_id': message_id,
36
36
'date': headers.get('date', '2005-01-01'),
37
37
'subject': headers.get('subject', 'subject'),
38
'author': headers.get('author', 'author'),
322
323
def test_get_messages(self):
323
324
client = GrackleClient('localhost', 8435)
324
with ForkedFakeService.from_client(client,
326
[make_message('foo'),
327
make_message('bar')]}):
326
'baz': [make_message('foo'), make_message('bar')]}
327
with ForkedFakeService.from_client(client, archive):
328
328
response = client.get_messages('baz')
329
329
self.assertEqual(['bar', 'foo'], sorted(m['message_id'] for m in
330
330
response['messages']))
334
334
def test_get_messages_by_id(self):
335
335
client = GrackleClient('localhost', 8437)
336
with ForkedFakeService.from_client(client,
338
[make_message('foo'),
339
make_message('bar')]}):
337
'baz': [make_message('foo'), make_message('bar')]}
338
with ForkedFakeService.from_client(client, archive):
340
339
response = client.get_messages('baz', message_ids=['foo'])
341
340
message, = response['messages']
342
341
self.assertEqual('foo', message['message_id'])
344
343
def test_get_messages_batching(self):
345
344
client = GrackleClient('localhost', 8438)
346
with ForkedFakeService.from_client(client,
348
[make_message('foo'),
349
make_message('bar')]}):
345
archive = {'baz': [make_message('foo'), make_message('bar')]}
346
with ForkedFakeService.from_client(client, archive):
350
347
response = client.get_messages('baz', limit=1)
351
348
self.assertEqual(1, len(response['messages']))
352
349
messages = response['messages']
359
356
def get_messages_member_order_test(self, key):
360
357
client = GrackleClient('localhost', 8439)
361
with ForkedFakeService.from_client(client,
363
{'message_id': 'foo', key: '2011-03-25'},
364
{'message_id': 'bar', key: '2011-03-24'}]}):
360
make_message('foo', headers={key: '2011-03-25'}),
361
make_message('bar', headers={key: '2011-03-24'}),
363
with ForkedFakeService.from_client(client, archive):
365
364
response = client.get_messages('baz')
366
365
self.assertIDOrder(['foo', 'bar'], response['messages'])
367
366
response = client.get_messages('baz', order=key)
377
376
self.get_messages_member_order_test('subject')
379
378
def test_get_messages_thread_subject_order(self):
381
make_message('bar', headers={'subject': 'y'}),
382
make_message('qux', headers={'subject': 'z'}),
383
make_message('foo', headers={'subject': 'x',
384
'in-reply-to': 'qux'})]}
381
make_message('bar', headers={'subject': 'y'}),
382
make_message('qux', headers={'subject': 'z'}),
383
make_message('foo', headers={'subject': 'x',
384
'in-reply-to': 'qux'}),
385
386
client = GrackleClient('localhost', 8439)
386
387
with ForkedFakeService.from_client(client, archive):
387
388
response = client.get_messages('baz')
394
395
def test_get_messages_thread_oldest_order(self):
395
396
client = GrackleClient('localhost', 8439)
397
make_message('bar', headers={'date': 'x'}),
398
make_message('qux', headers={'date': 'z'}),
399
make_message('foo', headers={'date': 'y', 'in-reply-to': 'qux'}),
399
make_message('bar', headers={'date': 'x'}),
400
make_message('qux', headers={'date': 'z'}),
401
make_message('foo', headers={'date': 'y',
402
'in-reply-to': 'qux'}),
401
404
with ForkedFakeService.from_client(client, archive):
402
405
response = client.get_messages('baz')
409
412
def test_get_messages_thread_newest_order(self):
410
413
client = GrackleClient('localhost', 8439)
411
with ForkedFakeService.from_client(client, {'baz': [
412
make_message('bar', headers={'date': 'x'}),
413
make_message('qux', headers={'date': 'w'}),
414
make_message('foo', headers={'date': 'y', 'in-reply-to': 'bar'}),
415
make_message('baz', headers={'date': 'z', 'in-reply-to': 'qux'}),
416
make_message('bar', headers={'date': 'x'}),
417
make_message('qux', headers={'date': 'w'}),
418
make_message('foo', headers={'date': 'y',
419
'in-reply-to': 'bar'}),
420
make_message('baz', headers={'date': 'z',
421
'in-reply-to': 'qux'}),
423
with ForkedFakeService.from_client(client, archive):
417
424
response = client.get_messages('baz', order='date')
418
425
self.assertIDOrder(
419
426
['qux', 'bar', 'foo', 'baz'], response['messages'])
424
431
def test_get_messages_unsupported_order(self):
425
432
client = GrackleClient('localhost', 8439)
426
with ForkedFakeService.from_client(client,
428
435
make_message('foo', headers={'date': '2011-03-25'}),
429
make_message('foo', headers={'date': '2011-03-24'})]}):
436
make_message('foo', headers={'date': '2011-03-24'}),
438
with ForkedFakeService.from_client(client, archive):
430
439
with ExpectedException(UnsupportedOrder, ''):
431
440
client.get_messages('baz', order='nonsense')
433
442
def test_get_messages_headers_no_headers(self):
434
443
client = GrackleClient('localhost', 8440)
435
with ForkedFakeService.from_client(client,
437
[make_message('foo')]}):
444
archive = {'baz': [make_message('foo')]}
445
with ForkedFakeService.from_client(client, archive):
438
446
response = client.get_messages('baz', headers=[
439
447
'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
440
448
first_message = response['messages'][0]
444
452
def test_get_messages_headers_exclude_headers(self):
445
453
client = GrackleClient('localhost', 8441)
446
with ForkedFakeService.from_client(client,
448
make_message('foo', headers={'From': 'me'})]}):
455
'baz': [make_message('foo', headers={'From': 'me'})]}
456
with ForkedFakeService.from_client(client, archive):
449
457
response = client.get_messages('baz', headers=[
450
458
'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
451
459
first_message = response['messages'][0]
455
463
def test_get_messages_headers_include_headers(self):
456
464
client = GrackleClient('localhost', 8442)
457
with ForkedFakeService.from_client(client,
459
make_message('foo', headers={'From': 'me', 'To': 'you'})]}):
467
make_message('foo', headers={'From': 'me', 'To': 'you'})]}
468
with ForkedFakeService.from_client(client, archive):
460
469
response = client.get_messages('baz', headers=[
462
471
first_message = response['messages'][0]
466
475
def test_get_messages_max_body_length(self):
467
476
client = GrackleClient('localhost', 8443)
468
with ForkedFakeService.from_client(client,
470
make_message('foo', body=u'abcdefghi')]}):
477
archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
478
with ForkedFakeService.from_client(client, archive):
471
479
response = client.get_messages('baz', max_body_length=3)
472
480
first_message = response['messages'][0]
473
481
self.assertEqual('abc', first_message['body'])
475
483
def test_include_hidden(self):
476
484
client = GrackleClient('localhost', 8444)
477
with ForkedFakeService.from_client(client,
479
487
make_message('foo', hidden=True),
480
make_message('bar', hidden=False)]}):
488
make_message('bar', hidden=False),
490
with ForkedFakeService.from_client(client, archive):
481
491
response = client.get_messages('baz', include_hidden=True)
482
492
self.assertMessageIDs(['bar', 'foo'], response['messages'])
483
493
response = client.get_messages('baz', include_hidden=False)
486
496
def test_display_type_unknown_value(self):
487
497
client = GrackleClient('localhost', 8445)
488
with ForkedFakeService.from_client(client,
490
make_message('foo', body=u'abcdefghi')]}):
498
archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
499
with ForkedFakeService.from_client(client, archive):
491
500
with ExpectedException(UnsupportedDisplayType, ''):
492
501
client.get_messages('baz', display_type='unknown')
494
503
def test_display_type_headers_only(self):
495
504
client = GrackleClient('localhost', 8446)
496
with ForkedFakeService.from_client(client,
498
507
make_message('foo', body=u'abcdefghi',
499
headers={'From': 'me', 'To': 'you'})]}):
508
headers={'From': 'me', 'To': 'you'})]}
509
with ForkedFakeService.from_client(client, archive):
500
510
response = client.get_messages('baz', display_type='headers-only')
501
511
first_message = response['messages'][0]
502
512
self.assertEqual('foo', first_message['message_id'])
508
518
def test_display_type_text_only(self):
509
519
client = GrackleClient('localhost', 8446)
510
with ForkedFakeService.from_client(client,
512
522
make_mime_message(
513
523
'foo', 'abcdefghi',
514
524
headers={'From': 'me', 'To': 'you'},
515
attachment_type='text/x-diff')
525
attachment_type='text/x-diff')]}
526
with ForkedFakeService.from_client(client, archive):
517
527
response = client.get_messages('baz', display_type='text-only')
518
528
first_message = response['messages'][0]
519
529
self.assertEqual('foo', first_message['message_id'])
524
534
def test_display_type_all(self):
525
535
client = GrackleClient('localhost', 8447)
526
with ForkedFakeService.from_client(client,
528
538
make_mime_message(
529
539
'foo', 'abcdefghi',
530
540
headers={'From': 'me', 'To': 'you'},
531
attachment_type='text/x-diff')
541
attachment_type='text/x-diff')]}
542
with ForkedFakeService.from_client(client, archive):
533
543
response = client.get_messages('baz', display_type='all')
534
544
first_message = response['messages'][0]
535
545
self.assertEqual('foo', first_message['message_id'])