~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:44:20 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: curtis.hovey@canonical.com-20120130184420-l5hilskyel3jyx02
Renamed ForkedFake => ForkedFakeService.

Show diffs side-by-side

added added

removed removed

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