~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-31 04:50:10 UTC
  • mto: (6.1.31 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120131045010-66k7k6n6i3kyrq9r
Create the archive outside of the call to create the server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    )
26
26
 
27
27
 
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:
30
30
        headers = {}
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'),
38
39
        'hidden': hidden,
39
40
        'attachments': [],
40
41
        'body': body,
321
322
 
322
323
    def test_get_messages(self):
323
324
        client = GrackleClient('localhost', 8435)
324
 
        with ForkedFakeService.from_client(client,
325
 
            {'baz':
326
 
                [make_message('foo'),
327
 
                 make_message('bar')]}):
 
325
        archive = {
 
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']))
333
333
 
334
334
    def test_get_messages_by_id(self):
335
335
        client = GrackleClient('localhost', 8437)
336
 
        with ForkedFakeService.from_client(client,
337
 
            {'baz':
338
 
                [make_message('foo'),
339
 
                 make_message('bar')]}):
 
336
        archive = {
 
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'])
343
342
 
344
343
    def test_get_messages_batching(self):
345
344
        client = GrackleClient('localhost', 8438)
346
 
        with ForkedFakeService.from_client(client,
347
 
            {'baz':
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']
358
355
 
359
356
    def get_messages_member_order_test(self, key):
360
357
        client = GrackleClient('localhost', 8439)
361
 
        with ForkedFakeService.from_client(client,
362
 
            {'baz': [
363
 
                 {'message_id': 'foo', key: '2011-03-25'},
364
 
                 {'message_id': 'bar', key: '2011-03-24'}]}):
 
358
        archive = {
 
359
            'baz': [
 
360
                make_message('foo', headers={key: '2011-03-25'}),
 
361
                make_message('bar', headers={key: '2011-03-24'}),
 
362
             ]}
 
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')
378
377
 
379
378
    def test_get_messages_thread_subject_order(self):
380
 
        archive = {'baz': [
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'})]}
 
379
        archive = {
 
380
            'baz': [
 
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
             ]}
385
386
        client = GrackleClient('localhost', 8439)
386
387
        with ForkedFakeService.from_client(client, archive):
387
388
            response = client.get_messages('baz')
393
394
 
394
395
    def test_get_messages_thread_oldest_order(self):
395
396
        client = GrackleClient('localhost', 8439)
396
 
        archive = {'baz': [
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'}),
 
397
        archive = {
 
398
            'baz': [
 
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'}),
400
403
            ]}
401
404
        with ForkedFakeService.from_client(client, archive):
402
405
            response = client.get_messages('baz')
408
411
 
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
 
            ]}):
 
414
        archive = {
 
415
            'baz': [
 
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'}),
 
422
            ]}
 
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'])
423
430
 
424
431
    def test_get_messages_unsupported_order(self):
425
432
        client = GrackleClient('localhost', 8439)
426
 
        with ForkedFakeService.from_client(client,
427
 
            {'baz': [
 
433
        archive = {
 
434
            'baz': [
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'}),
 
437
            ]}
 
438
        with ForkedFakeService.from_client(client, archive):
430
439
            with ExpectedException(UnsupportedOrder, ''):
431
440
                client.get_messages('baz', order='nonsense')
432
441
 
433
442
    def test_get_messages_headers_no_headers(self):
434
443
        client = GrackleClient('localhost', 8440)
435
 
        with ForkedFakeService.from_client(client,
436
 
            {'baz':
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]
443
451
 
444
452
    def test_get_messages_headers_exclude_headers(self):
445
453
        client = GrackleClient('localhost', 8441)
446
 
        with ForkedFakeService.from_client(client,
447
 
            {'baz': [
448
 
                make_message('foo', headers={'From': 'me'})]}):
 
454
        archive = {
 
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]
454
462
 
455
463
    def test_get_messages_headers_include_headers(self):
456
464
        client = GrackleClient('localhost', 8442)
457
 
        with ForkedFakeService.from_client(client,
458
 
            {'baz': [
459
 
                make_message('foo', headers={'From': 'me', 'To': 'you'})]}):
 
465
        archive = {
 
466
            'baz': [
 
467
                make_message('foo', headers={'From': 'me', 'To': 'you'})]}
 
468
        with ForkedFakeService.from_client(client, archive):
460
469
            response = client.get_messages('baz', headers=[
461
470
                'From', 'To'])
462
471
        first_message = response['messages'][0]
465
474
 
466
475
    def test_get_messages_max_body_length(self):
467
476
        client = GrackleClient('localhost', 8443)
468
 
        with ForkedFakeService.from_client(client,
469
 
            {'baz': [
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'])
474
482
 
475
483
    def test_include_hidden(self):
476
484
        client = GrackleClient('localhost', 8444)
477
 
        with ForkedFakeService.from_client(client,
478
 
            {'baz': [
 
485
        archive = {
 
486
            'baz': [
479
487
                make_message('foo', hidden=True),
480
 
                make_message('bar', hidden=False)]}):
 
488
                make_message('bar', hidden=False),
 
489
            ]}
 
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)
485
495
 
486
496
    def test_display_type_unknown_value(self):
487
497
        client = GrackleClient('localhost', 8445)
488
 
        with ForkedFakeService.from_client(client,
489
 
            {'baz': [
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')
493
502
 
494
503
    def test_display_type_headers_only(self):
495
504
        client = GrackleClient('localhost', 8446)
496
 
        with ForkedFakeService.from_client(client,
497
 
            {'baz': [
 
505
        archive = {
 
506
            'baz': [
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'])
507
517
 
508
518
    def test_display_type_text_only(self):
509
519
        client = GrackleClient('localhost', 8446)
510
 
        with ForkedFakeService.from_client(client,
511
 
            {'baz': [
 
520
        archive = {
 
521
            'baz': [
512
522
                make_mime_message(
513
523
                    'foo', 'abcdefghi',
514
524
                    headers={'From': 'me', 'To': 'you'},
515
 
                    attachment_type='text/x-diff')
516
 
            ]}):
 
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'])
523
533
 
524
534
    def test_display_type_all(self):
525
535
        client = GrackleClient('localhost', 8447)
526
 
        with ForkedFakeService.from_client(client,
527
 
            {'baz': [
 
536
        archive = {
 
537
            'baz': [
528
538
                make_mime_message(
529
539
                    'foo', 'abcdefghi',
530
540
                    headers={'From': 'me', 'To': 'you'},
531
 
                    attachment_type='text/x-diff')
532
 
            ]}):
 
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'])