~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-30 18:30:54 UTC
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: curtis.hovey@canonical.com-20120130183054-lyjgaxcekr8efuou
Hush lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
        return response
118
118
 
119
119
 
120
 
class ForkedFakeService:
 
120
class ForkedFake:
121
121
    """A Grackle service fake, as a ContextManager."""
122
122
 
123
123
    def __init__(self, port, messages=None, write_logs=False):
124
124
        """Constructor.
125
 
 
126
 
        :param port: The tcp port to use.
 
125
        :param port: The tcp port to use
127
126
        :param messages: A dict of lists of dicts representing messages.  The
128
127
            outer dict represents the archive, the list represents the list of
129
128
            messages for that archive.
140
139
 
141
140
    @staticmethod
142
141
    def from_client(client, messages=None):
143
 
        """Instantiate a ForkedFakeService from the client.
 
142
        """Instantiate a ForkedFake from the client.
144
143
 
145
 
        :param port: The client to provide service for.
 
144
        :param port: The client  to provide service for.
146
145
        :param messages: A dict of lists of dicts representing messages.  The
147
146
            outer dict represents the archive, the list represents the list of
148
147
            messages for that archive.
149
148
        """
150
 
        return ForkedFakeService(client.port, messages)
 
149
        return ForkedFake(client.port, messages)
151
150
 
152
151
    def is_ready(self):
153
152
        """Tell the parent process that the server is ready for writes."""
233
232
 
234
233
    def test_put_message(self):
235
234
        client = GrackleClient('localhost', 8436)
236
 
        with ForkedFakeService.from_client(client):
 
235
        with ForkedFake.from_client(client):
237
236
            client.put_message('arch1', 'asdf', StringIO('This is a message'))
238
237
            with ExpectedException(Exception, 'wtf'):
239
238
                client.put_message('arch1', 'asdf',
251
250
 
252
251
    def test_get_messages(self):
253
252
        client = GrackleClient('localhost', 8435)
254
 
        with ForkedFakeService.from_client(client,
 
253
        with ForkedFake.from_client(client,
255
254
            {'baz':
256
255
            [{'message_id': 'foo'},
257
256
             {'message_id': 'bar'}]}):
263
262
 
264
263
    def test_get_messages_by_id(self):
265
264
        client = GrackleClient('localhost', 8437)
266
 
        with ForkedFakeService.from_client(client,
 
265
        with ForkedFake.from_client(client,
267
266
            {'baz':
268
267
            [{'message_id': 'foo'},
269
268
             {'message_id': 'bar'}]}):
273
272
 
274
273
    def test_get_messages_batching(self):
275
274
        client = GrackleClient('localhost', 8438)
276
 
        with ForkedFakeService.from_client(client,
 
275
        with ForkedFake.from_client(client,
277
276
            {'baz':
278
277
            [{'message_id': 'foo'},
279
278
             {'message_id': 'bar'}]}):
288
287
 
289
288
    def get_messages_member_order_test(self, key):
290
289
        client = GrackleClient('localhost', 8439)
291
 
        with ForkedFakeService.from_client(client,
 
290
        with ForkedFake.from_client(client,
292
291
                {'baz': [{'message_id': 'foo', key: '2011-03-25'},
293
292
                 {'message_id': 'bar', key: '2011-03-24'}]}):
294
293
            response = client.get_messages('baz')
307
306
 
308
307
    def test_get_messages_thread_subject_order(self):
309
308
        client = GrackleClient('localhost', 8439)
310
 
        with ForkedFakeService.from_client(client, {'baz': [
 
309
        with ForkedFake.from_client(client, {'baz': [
311
310
            {'message_id': 'bar', 'subject': 'y'},
312
311
            {'message_id': 'qux', 'subject': 'z'},
313
312
            {'message_id': 'foo', 'subject': 'x', 'in_reply_to': 'qux'},
321
320
 
322
321
    def test_get_messages_thread_oldest_order(self):
323
322
        client = GrackleClient('localhost', 8439)
324
 
        with ForkedFakeService.from_client(client, {'baz': [
 
323
        with ForkedFake.from_client(client, {'baz': [
325
324
            {'message_id': 'bar', 'date': 'x'},
326
325
            {'message_id': 'qux', 'date': 'z'},
327
326
            {'message_id': 'foo', 'date': 'y', 'in_reply_to': 'qux'},
335
334
 
336
335
    def test_get_messages_thread_newest_order(self):
337
336
        client = GrackleClient('localhost', 8439)
338
 
        with ForkedFakeService.from_client(client, {'baz': [
 
337
        with ForkedFake.from_client(client, {'baz': [
339
338
            {'message_id': 'bar', 'date': 'x'},
340
339
            {'message_id': 'qux', 'date': 'w'},
341
340
            {'message_id': 'foo', 'date': 'y', 'in_reply_to': 'bar'},
350
349
 
351
350
    def test_get_messages_unsupported_order(self):
352
351
        client = GrackleClient('localhost', 8439)
353
 
        with ForkedFakeService.from_client(client,
 
352
        with ForkedFake.from_client(client,
354
353
                {'baz': [{'message_id': 'foo', 'date': '2011-03-25'},
355
354
                 {'message_id': 'bar', 'date': '2011-03-24'}]}):
356
355
            with ExpectedException(UnsupportedOrder, ''):
358
357
 
359
358
    def test_get_messages_headers_no_headers(self):
360
359
        client = GrackleClient('localhost', 8440)
361
 
        with ForkedFakeService.from_client(client,
 
360
        with ForkedFake.from_client(client,
362
361
            {'baz': [
363
362
                {'message_id': 'foo'}
364
363
            ]}):
370
369
 
371
370
    def test_get_messages_headers_exclude_headers(self):
372
371
        client = GrackleClient('localhost', 8441)
373
 
        with ForkedFakeService.from_client(client,
 
372
        with ForkedFake.from_client(client,
374
373
            {'baz': [
375
374
                {'message_id': 'foo', 'headers': {'From': 'me'}}
376
375
            ]}):
382
381
 
383
382
    def test_get_messages_headers_include_headers(self):
384
383
        client = GrackleClient('localhost', 8442)
385
 
        with ForkedFakeService.from_client(client,
 
384
        with ForkedFake.from_client(client,
386
385
            {'baz': [
387
386
                {'message_id': 'foo', 'headers': {'From': 'me', 'To': 'you'}}
388
387
            ]}):
394
393
 
395
394
    def test_get_messages_max_body_length(self):
396
395
        client = GrackleClient('localhost', 8443)
397
 
        with ForkedFakeService.from_client(client,
 
396
        with ForkedFake.from_client(client,
398
397
            {'baz': [
399
398
                {'message_id': 'foo', 'body': u'abcdefghi'}
400
399
            ]}):
404
403
 
405
404
    def test_include_hidden(self):
406
405
        client = GrackleClient('localhost', 8444)
407
 
        with ForkedFakeService.from_client(client,
 
406
        with ForkedFake.from_client(client,
408
407
            {'baz': [
409
408
                {'message_id': 'foo', 'hidden': True},
410
409
                {'message_id': 'bar', 'hidden': False}