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

« back to all changes in this revision

Viewing changes to ivle/webapp/base/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:
37
37
            setattr(self, key, kwargs[key])
38
38
 
39
39
    def render(self, req):
40
 
        if req.method == 'GET':
41
 
            outstr = self.GET(req)
42
 
        # XXX PATCH hack
43
 
        if req.method == 'PUT':
44
 
            outstr = self.PATCH(req, req.read())
45
 
        req.content_type = self.content_type
46
 
        req.write(outstr)
 
40
        raise NotImplementedError()
47
41
 
48
42
class JSONRESTView(RESTView):
49
43
    """
98
92
            # we are OK.
99
93
            unspec = set(args) - set(opargs.keys())
100
94
            if unspec and not defaults:
101
 
                raise BadRequest('Missing arguments: ' + ','.join(unspec))
 
95
                raise BadRequest('Missing arguments: ' + ', '.join(unspec))
102
96
 
103
97
            unspec = [k for k in unspec if k not in args[-len(defaults):]]
104
98
 
105
99
            if unspec:
106
 
                raise BadRequest('Missing arguments: ' + ','.join(unspec))
 
100
                raise BadRequest('Missing arguments: ' + ', '.join(unspec))
107
101
 
108
102
            # We have extra arguments if the are no match args in the function
109
103
            # signature, AND there is no **.
112
106
                raise BadRequest('Extra arguments: ' + ', '.join(extra))
113
107
 
114
108
            outjson = op(req, **opargs)
115
 
        else:
116
 
            raise AssertionError('Unknown method somehow got through.')
117
109
 
118
110
        req.content_type = self.content_type
119
111
        if outjson is not None: