~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-12 09:54:51 UTC
  • mto: (6.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: aaron@canonical.com-20120112095451-6hwsm1c1demeokl5
Support order by date

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
        messages = [m for m in self.server.messages[archive] if 'message_ids'
70
70
                    not in parameters or m['message_id'] in
71
71
                    parameters['message_ids']]
 
72
        if 'order' in parameters:
 
73
            messages.sort(key=lambda m: m[parameters['order']])
72
74
        limit = parameters.get('limit', 100)
73
75
        memo = parameters.get('memo')
74
76
        message_id_indices = dict(
114
116
 
115
117
class TestGetMessages(TestCase):
116
118
 
 
119
    def assertIDOrder(self, ids, messages):
 
120
        self.assertEqual(ids, [m['message_id'] for m in messages])
 
121
 
117
122
    def assertMessageIDs(self, ids, messages):
118
 
        self.assertEqual(
119
 
            sorted(ids), sorted(m['message_id'] for m in messages))
 
123
        self.assertIDOrder(
 
124
            sorted(ids), sorted(messages, key=lambda m:m['message_id']))
120
125
 
121
126
    def test_get_messages(self):
122
127
        client = GrackleClient('localhost', 8435)
141
146
        self.assertEqual('foo', message['message_id'])
142
147
 
143
148
    def test_get_messages_batching(self):
144
 
        client = GrackleClient('localhost', 8437)
 
149
        client = GrackleClient('localhost', 8438)
145
150
        with fake_grackle_service(client,
146
151
            {'baz':
147
152
            [{'message_id': 'foo'},
154
159
            self.assertEqual(1, len(response['messages']))
155
160
            messages.extend(response['messages'])
156
161
            self.assertMessageIDs(['foo', 'bar'], messages)
 
162
 
 
163
    def test_get_messages_date_order(self):
 
164
        client = GrackleClient('localhost', 8439)
 
165
        with fake_grackle_service(client,
 
166
                {'baz': [{'message_id': 'foo', 'date': '2011-03-25'},
 
167
                 {'message_id': 'bar', 'date': '2011-03-24'}]}):
 
168
            response = client.get_messages('baz')
 
169
            self.assertIDOrder(['foo', 'bar'], response['messages'])
 
170
            response = client.get_messages('baz', order='date')
 
171
            self.assertIDOrder(['bar', 'foo'], response['messages'])