~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Aaron Bentley
  • Date: 2012-01-16 15:23:42 UTC
  • Revision ID: aaron@canonical.com-20120116152342-a501e23hpygeyjai
Switch fake_grackle_service to ForkedFake.from_client.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
    def __init__(self, port, messages=None):
115
115
        self.pid = None
116
116
        self.port = port
117
 
        self.messages = messages
 
117
        if messages is None:
 
118
            self.messages = {}
 
119
        else:
 
120
            self.messages = messages
118
121
        self.read_end, self.write_end = os.pipe()
119
122
 
 
123
    @staticmethod
 
124
    def from_client(client, messages=None):
 
125
        return ForkedFake(client.port, messages)
 
126
 
120
127
    def is_ready(self):
121
128
        os.write(self.write_end, 'asdf')
122
129
 
174
181
                return
175
182
 
176
183
 
177
 
def fake_grackle_service(client, messages=None):
178
 
    if messages is None:
179
 
        messages = {}
180
 
    return ForkedFake(client.port, messages)
181
 
 
182
 
 
183
184
class TestPutMessage(TestCase):
184
185
 
185
186
    def test_put_message(self):
186
187
        client = GrackleClient('localhost', 8436)
187
 
        with fake_grackle_service(client):
 
188
        with ForkedFake.from_client(client):
188
189
            client.put_message('arch1', 'asdf', StringIO('This is a message'))
189
190
            with ExpectedException(Exception, 'wtf'):
190
191
                client.put_message('arch1', 'asdf',
202
203
 
203
204
    def test_get_messages(self):
204
205
        client = GrackleClient('localhost', 8435)
205
 
        with fake_grackle_service(client,
 
206
        with ForkedFake.from_client(client,
206
207
            {'baz':
207
208
            [{'message_id': 'foo'},
208
209
             {'message_id': 'bar'}]}):
214
215
 
215
216
    def test_get_messages_by_id(self):
216
217
        client = GrackleClient('localhost', 8437)
217
 
        with fake_grackle_service(client,
 
218
        with ForkedFake.from_client(client,
218
219
            {'baz':
219
220
            [{'message_id': 'foo'},
220
221
             {'message_id': 'bar'}]}):
224
225
 
225
226
    def test_get_messages_batching(self):
226
227
        client = GrackleClient('localhost', 8438)
227
 
        with fake_grackle_service(client,
 
228
        with ForkedFake.from_client(client,
228
229
            {'baz':
229
230
            [{'message_id': 'foo'},
230
231
             {'message_id': 'bar'}]}):
239
240
 
240
241
    def get_messages_member_order_test(self, key):
241
242
        client = GrackleClient('localhost', 8439)
242
 
        with fake_grackle_service(client,
 
243
        with ForkedFake.from_client(client,
243
244
                {'baz': [{'message_id': 'foo', key: '2011-03-25'},
244
245
                 {'message_id': 'bar', key: '2011-03-24'}]}):
245
246
            response = client.get_messages('baz')
258
259
 
259
260
    def test_get_messages_thread_subject_order(self):
260
261
        client = GrackleClient('localhost', 8439)
261
 
        with fake_grackle_service(client, {'baz': [
 
262
        with ForkedFake.from_client(client, {'baz': [
262
263
            {'message_id': 'bar', 'subject': 'y'},
263
264
            {'message_id': 'qux', 'subject': 'z'},
264
265
            {'message_id': 'foo', 'subject': 'x', 'in_reply_to': 'qux'},
272
273
 
273
274
    def test_get_messages_thread_oldest_order(self):
274
275
        client = GrackleClient('localhost', 8439)
275
 
        with fake_grackle_service(client, {'baz': [
 
276
        with ForkedFake.from_client(client, {'baz': [
276
277
            {'message_id': 'bar', 'date': 'x'},
277
278
            {'message_id': 'qux', 'date': 'z'},
278
279
            {'message_id': 'foo', 'date': 'y', 'in_reply_to': 'qux'},
286
287
 
287
288
    def test_get_messages_thread_newest_order(self):
288
289
        client = GrackleClient('localhost', 8439)
289
 
        with fake_grackle_service(client, {'baz': [
 
290
        with ForkedFake.from_client(client, {'baz': [
290
291
            {'message_id': 'bar', 'date': 'x'},
291
292
            {'message_id': 'qux', 'date': 'w'},
292
293
            {'message_id': 'foo', 'date': 'y', 'in_reply_to': 'bar'},
301
302
 
302
303
    def test_get_messages_unsupported_order(self):
303
304
        client = GrackleClient('localhost', 8439)
304
 
        with fake_grackle_service(client,
 
305
        with ForkedFake.from_client(client,
305
306
                {'baz': [{'message_id': 'foo', 'date': '2011-03-25'},
306
307
                 {'message_id': 'bar', 'date': '2011-03-24'}]}):
307
308
            with ExpectedException(UnsupportedOrder):
309
310
 
310
311
    def test_get_messages_headers_no_headers(self):
311
312
        client = GrackleClient('localhost', 8440)
312
 
        with fake_grackle_service(client,
 
313
        with ForkedFake.from_client(client,
313
314
            {'baz': [
314
315
                {'message_id': 'foo'}
315
316
            ]}):
321
322
 
322
323
    def test_get_messages_headers_exclude_headers(self):
323
324
        client = GrackleClient('localhost', 8441)
324
 
        with fake_grackle_service(client,
 
325
        with ForkedFake.from_client(client,
325
326
            {'baz': [
326
327
                {'message_id': 'foo', 'headers': {'From': 'me'}}
327
328
            ]}):
333
334
 
334
335
    def test_get_messages_headers_include_headers(self):
335
336
        client = GrackleClient('localhost', 8442)
336
 
        with fake_grackle_service(client,
 
337
        with ForkedFake.from_client(client,
337
338
            {'baz': [
338
339
                {'message_id': 'foo', 'headers': {'From': 'me', 'To': 'you'}}
339
340
            ]}):
345
346
 
346
347
    def test_get_messages_max_body_length(self):
347
348
        client = GrackleClient('localhost', 8443)
348
 
        with fake_grackle_service(client,
 
349
        with ForkedFake.from_client(client,
349
350
            {'baz': [
350
351
                {'message_id': 'foo', 'body': u'abcdefghi'}
351
352
            ]}):
355
356
 
356
357
    def test_include_hidden(self):
357
358
        client = GrackleClient('localhost', 8444)
358
 
        with fake_grackle_service(client,
 
359
        with ForkedFake.from_client(client,
359
360
            {'baz': [
360
361
                {'message_id': 'foo', 'hidden': True},
361
362
                {'message_id': 'bar', 'hidden': False}