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

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-30 18:31:19 UTC
  • mfrom: (6.2.2 client-get-messages-0)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120130183119-ylmo65mur5ogktud
Merged lint fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        parameters = simplejson.loads(query['parameters'][0])
55
55
        order = parameters.get('order')
56
56
        messages = self.messages[archive_id]
57
 
        if order is not None :
 
57
        if order is not None:
58
58
            if order not in SUPPORTED_ORDERS:
59
59
                raise UnsupportedOrder
60
60
            elif order.startswith('thread_'):
72
72
                messages.sort(key=lambda m: m[order])
73
73
        new_messages = []
74
74
        for message in messages:
75
 
            if (
76
 
                not parameters['include_hidden']
 
75
            if (not parameters['include_hidden']
77
76
                and message.get('hidden', False)):
78
77
                continue
79
78
 
80
 
            if ('message_ids' in parameters and
81
 
                message['message_id'] not in parameters['message_ids']):
 
79
            if ('message_ids' in parameters
 
80
                and message['message_id'] not in parameters['message_ids']):
82
81
                continue
83
82
            message = dict(message)
84
83
            if 'headers' in parameters:
118
117
        return response
119
118
 
120
119
 
121
 
 
122
120
class ForkedFake:
123
121
    """A Grackle service fake, as a ContextManager."""
124
122
 
226
224
    def log_message(self, format, *args):
227
225
        """Override log_message to use standard Python logging."""
228
226
        message = "%s - - [%s] %s\n" % (
229
 
            self.address_string(), self.log_date_time_string(), format%args)
 
227
            self.address_string(), self.log_date_time_string(), format % args)
230
228
        self.logger.info(message)
231
229
 
232
230
 
248
246
 
249
247
    def assertMessageIDs(self, ids, messages):
250
248
        self.assertIDOrder(
251
 
            sorted(ids), sorted(messages, key=lambda m:m['message_id']))
 
249
            sorted(ids), sorted(messages, key=lambda m: m['message_id']))
252
250
 
253
251
    def test_get_messages(self):
254
252
        client = GrackleClient('localhost', 8435)
414
412
            self.assertMessageIDs(['bar', 'foo'], response['messages'])
415
413
            response = client.get_messages('baz', include_hidden=False)
416
414
            self.assertMessageIDs(['bar'], response['messages'])
417