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

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Aaron Bentley
  • Date: 2012-01-13 14:30:09 UTC
  • mto: (6.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: aaron@canonical.com-20120113143009-t0kzaz3czxnv1nwz
get_messagesĀ supportsĀ headerĀ parameter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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', {})
59
62
        self.is_ready()
60
63
        service.serve_forever()
61
64
 
132
135
        else:
133
136
            next_memo = None
134
137
        messages = messages[start:end]
 
138
        new_messages = []
 
139
        for message in messages:
 
140
            message = dict(message)
 
141
            if 'headers' in parameters:
 
142
                headers = dict(
 
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)
135
147
        response = {
136
 
            'messages': messages,
 
148
            'messages': new_messages,
137
149
            'next_memo': next_memo,
138
150
            'previous_memo': previous_memo
139
151
            }
272
284
                 {'message_id': 'bar', 'date': '2011-03-24'}]}):
273
285
            with ExpectedException(UnsupportedOrder):
274
286
                client.get_messages('baz', order='nonsense')
 
287
 
 
288
    def test_get_messages_headers_no_headers(self):
 
289
        client = GrackleClient('localhost', 8440)
 
290
        with fake_grackle_service(client,
 
291
            {'baz': [
 
292
                {'message_id': 'foo'}
 
293
            ]}):
 
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'])
 
299
 
 
300
    def test_get_messages_headers_exclude_headers(self):
 
301
        client = GrackleClient('localhost', 8440)
 
302
        with fake_grackle_service(client,
 
303
            {'baz': [
 
304
                {'message_id': 'foo', 'headers': {'From': 'me'}}
 
305
            ]}):
 
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'])
 
311
 
 
312
    def test_get_messages_headers_include_headers(self):
 
313
        client = GrackleClient('localhost', 8440)
 
314
        with fake_grackle_service(client,
 
315
            {'baz': [
 
316
                {'message_id': 'foo', 'headers': {'From': 'me', 'To': 'you'}}
 
317
            ]}):
 
318
            response = client.get_messages('baz', headers=[
 
319
                'From', 'To'])
 
320
        first_message = response['messages'][0]
 
321
        self.assertEqual('foo', first_message['message_id'])
 
322
        self.assertEqual({'From': 'me', 'To': 'you'}, first_message['headers'])