Example #1
0
    def _do_request(self, data):
        """Make a request to the endpoint with `data` in the body.

        `data` should be a string -- the server will expect valid json, but
        we want to write test cases with invalid input as well.
        """
        req = Request(wsgi_mkenv('POST', '/give-me-an-e', data=data))
        return rest.request_handler(req)
Example #2
0
    def test_call_once(self):
        # We define an API call that increments a counter each time the
        # function is called, then invoke it via HTTP. Finally, we verify that
        # the counter is equal to 1, indicating that the function was called
        # the correct number of times.

        @rest.rest_call('POST', '/increment')
        def increment():
            """Increment a counter each time this function is called."""
            self.num_calls += 1

        rest.request_handler(Request(wsgi_mkenv('POST', '/increment')))
        assert self.num_calls == 1
Example #3
0
 def request(self):
     return wsgi_mkenv('GET', '/some_error')
Example #4
0
 def request(self):
     return wsgi_mkenv('POST', '/product',
                         data=json.dumps({'x': 2, 'y': 7}))
Example #5
0
 def request(self):
     return wsgi_mkenv('POST', '/func/foo',
                       data=json.dumps({'bar': 'bonnie', 'baz': 'clyde'}))
Example #6
0
 def request(self):
     return wsgi_mkenv('GET', '/foo')
Example #7
0
 def request(self):
     return wsgi_mkenv('GET', '/func/alice/bob')