~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-31 05:11:49 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: curtis.hovey@canonical.com-20120131051149-8tqdz4i3xn2bowvv
Simplified the main loop conditions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        """Constructor."""
81
81
        self.messages = messages
82
82
 
 
83
    @staticmethod
 
84
    def is_multipart(message):
 
85
        return isinstance(message['body'], list)
 
86
 
83
87
    def get_messages(self, archive_id, query_string):
84
88
        """Return matching messages.
85
89
 
112
116
            raise UnsupportedDisplayType
113
117
        new_messages = []
114
118
        for message in messages:
115
 
            if (not parameters['include_hidden']
116
 
                and message.get('hidden', False)):
 
119
            if (not parameters['include_hidden'] and message['hidden']):
117
120
                continue
118
 
 
119
121
            if ('message_ids' in parameters
120
122
                and message['message_id'] not in parameters['message_ids']):
121
123
                continue
125
127
                    (k, v) for k, v in message['headers'].iteritems()
126
128
                    if k in parameters['headers'])
127
129
                message['headers'] = headers
128
 
            max_body = parameters.get('max_body_length')
129
130
            if display_type == 'headers-only':
130
131
                del message['body']
131
 
            elif (display_type == 'text-only'
132
 
                  and isinstance(message['body'], list)):
 
132
            elif display_type == 'text-only' and self.is_multipart(message):
133
133
                text_parts = [
134
134
                    part.get_payload() for part in message['body']
135
135
                    if part.get_content_type() == 'text/plain']
136
136
                message['body'] = '\n\n'.join(text_parts)
137
 
            elif (display_type == 'all'
138
 
                  and isinstance(message['body'], list)):
 
137
            elif display_type == 'all' and self.is_multipart(message):
139
138
                parts = [str(part.get_payload()) for part in message['body']]
140
139
                message['body'] = '\n\n'.join(parts)
 
140
            max_body = parameters.get('max_body_length')
141
141
            if max_body is not None and display_type != 'headers-only':
142
142
                message['body'] = message['body'][:max_body]
143
143
            new_messages.append(message)