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

« back to all changes in this revision

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

ivle.webapp.base.views#JSONRESTView: Named operations now take the request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
                'result': data['result'], 'test': data['test']}
15
15
 
16
16
    @named_operation
17
 
    def do_stuff(self, what):
 
17
    def do_stuff(self, req, what):
18
18
        return {'result': 'Did %s!' % what}
19
19
 
20
20
    @named_operation
21
 
    def say_something(self, thing='nothing'):
 
21
    def say_something(self, req, thing='nothing'):
22
22
        return {'result': 'Said %s!' % thing}
23
23
 
 
24
    @named_operation
 
25
    def get_req_method(self, req):
 
26
        return {'method': req.method}
 
27
 
24
28
class JSONRESTViewTest(JSONRESTViewTestWithoutPUT):
25
29
    '''A small JSON REST view for testing purposes.'''
26
30
    def PUT(self, req, data):
191
195
        view.render(req)
192
196
        assert req.content_type == 'application/json'
193
197
        assert req.response_body == '{"result": "Said something!"}\n'
 
198
 
 
199
    def testNamedOperationUsingRequest(self):
 
200
        req = FakeRequest()
 
201
        req.method = 'POST'
 
202
        req.request_body = urllib.urlencode({'ivle.op': 'get_req_method'})
 
203
        view = JSONRESTViewTest(req)
 
204
        view.render(req)
 
205
        assert req.content_type == 'application/json'
 
206
        assert req.response_body == '{"method": "POST"}\n'