~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/test/test_rest.py

ivle.webapp.base.rest#RESTView: Remove broken old render() - it should be
                                implemented by subclasses.
                     #JSONRESTView: Remove an impossible assertion, and fix
                                    some exception message spacing.
ivle.webapp.base.test.test_rest: Add a named operation with both default and
                                 non-default arguments, and check that we die
                                 properly when the non-default is unspecified.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        return {'result': 'Said %s!' % thing}
23
23
 
24
24
    @named_operation
 
25
    def do_say_something(self, req, what, thing='nothing'):
 
26
        return {'result': 'Said %s and %s!' % (what, thing)}
 
27
 
 
28
    @named_operation
25
29
    def get_req_method(self, req):
26
30
        return {'method': req.method}
27
31
 
196
200
        assert req.content_type == 'application/json'
197
201
        assert req.response_body == '{"result": "Said something!"}\n'
198
202
 
 
203
    def testNamedOperationWithDefaultAndMissingArgs(self):
 
204
        req = FakeRequest()
 
205
        req.method = 'POST'
 
206
        req.request_body = urllib.urlencode({'ivle.op': 'do_say_something',
 
207
                                             'thing': 'something'})
 
208
        view = JSONRESTViewTest(req)
 
209
        try:
 
210
            view.render(req)
 
211
        except BadRequest, e:
 
212
            assert e.message == 'Missing arguments: what'
 
213
        else:
 
214
            raise AssertionError("did not raise BadRequest")
 
215
 
199
216
    def testNamedOperationUsingRequest(self):
200
217
        req = FakeRequest()
201
218
        req.method = 'POST'