~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 10:05:32 UTC
  • mto: (6.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: aaron@canonical.com-20120112100532-gljok11rzp7i3y11
TestĀ unsupportedĀ orders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from grackle.client import (
17
17
    GrackleClient,
 
18
    UnsupportedOrder,
18
19
    )
19
20
 
20
21
 
47
48
        os.kill(self.pid, SIGKILL)
48
49
 
49
50
 
 
51
SUPPORTED_ORDERS = set(['date'])
 
52
 
 
53
 
50
54
class FakeGrackleRequestHandler(BaseHTTPRequestHandler):
51
55
 
52
56
    def do_POST(self):
64
68
        archive = os.path.split(path)[1]
65
69
        query = parse_qs(query_string)
66
70
        parameters = simplejson.loads(query['parameters'][0])
67
 
        self.send_response(httplib.OK)
68
 
        self.end_headers()
69
71
        messages = [m for m in self.server.messages[archive] if 'message_ids'
70
72
                    not in parameters or m['message_id'] in
71
73
                    parameters['message_ids']]
72
74
        if 'order' in parameters:
 
75
            if parameters['order'] not in SUPPORTED_ORDERS:
 
76
                self.send_response(httplib.BAD_REQUEST)
 
77
                self.wfile.write('Unsupported order')
 
78
                return
73
79
            messages.sort(key=lambda m: m[parameters['order']])
 
80
        self.send_response(httplib.OK)
 
81
        self.end_headers()
74
82
        limit = parameters.get('limit', 100)
75
83
        memo = parameters.get('memo')
76
84
        message_id_indices = dict(
169
177
            self.assertIDOrder(['foo', 'bar'], response['messages'])
170
178
            response = client.get_messages('baz', order='date')
171
179
            self.assertIDOrder(['bar', 'foo'], response['messages'])
 
180
 
 
181
    def test_get_messages_unsupported_order(self):
 
182
        client = GrackleClient('localhost', 8439)
 
183
        with fake_grackle_service(client,
 
184
                {'baz': [{'message_id': 'foo', 'date': '2011-03-25'},
 
185
                 {'message_id': 'bar', 'date': '2011-03-24'}]}):
 
186
            with ExpectedException(UnsupportedOrder):
 
187
                client.get_messages('baz', order='nonsense')