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)
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
def request(self): return wsgi_mkenv('GET', '/some_error')
def request(self): return wsgi_mkenv('POST', '/product', data=json.dumps({'x': 2, 'y': 7}))
def request(self): return wsgi_mkenv('POST', '/func/foo', data=json.dumps({'bar': 'bonnie', 'baz': 'clyde'}))
def request(self): return wsgi_mkenv('GET', '/foo')
def request(self): return wsgi_mkenv('GET', '/func/alice/bob')