~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 00:00:49 UTC
  • mto: (6.1.31 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120131000049-5hv0eb60q5qwt55z
Added support for display_type == 'all'.
This has a hack because many of the tests are not working with a real message.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                text_parts = [
124
124
                    part.get_payload() for part in message['body']
125
125
                    if part.get_content_type() == 'text/plain']
126
 
                message['body'] = '\n'.join(text_parts)
127
 
            elif max_body is not None:
 
126
                message['body'] = '\n\n'.join(text_parts)
 
127
            elif (display_type == 'all'
 
128
                  and 'body' in message
 
129
                  and isinstance(message['body'], list)):
 
130
                parts = [str(part.get_payload()) for part in message['body']]
 
131
                message['body'] = '\n\n'.join(parts)
 
132
            if max_body is not None and display_type != 'headers-only':
128
133
                message['body'] = message['body'][:max_body]
129
 
            else:
130
 
                # display_type == 'all'
131
 
                pass
132
134
            new_messages.append(message)
133
135
        messages = new_messages
134
136
        limit = parameters.get('limit', 100)
499
501
        self.assertEqual('foo', first_message['message_id'])
500
502
        self.assertEqual('me', first_message['headers']['From'])
501
503
        self.assertEqual('you', first_message['headers']['To'])
502
 
        self.assertEqual(first_message['body'], 'abcdefghi')
 
504
        self.assertEqual('abcdefghi', first_message['body'])
 
505
 
 
506
    def test_display_type_all(self):
 
507
        client = GrackleClient('localhost', 8447)
 
508
        with ForkedFakeService.from_client(client,
 
509
            {'baz': [
 
510
                make_json_message(
 
511
                    'abcdefghi', message_id='foo',
 
512
                    headers={'From': 'me', 'To': 'you'},
 
513
                    attachment_type='text/x-diff')
 
514
            ]}):
 
515
            response = client.get_messages('baz', display_type='all')
 
516
        first_message = response['messages'][0]
 
517
        self.assertEqual('foo', first_message['message_id'])
 
518
        self.assertEqual('me', first_message['headers']['From'])
 
519
        self.assertEqual('you', first_message['headers']['To'])
 
520
        self.assertEqual(
 
521
            'abcdefghi\n\nattactment data.', first_message['body'])