def _data_request(self, path, data, content_type='application/json', method='POST', params={}): environ = self._environ(path) environ['REQUEST_METHOD'] = method req = wsgi.Request(environ) req.context = utils.dummy_context('api_test_user', self.tenant) self.context = req.context req.content_type = content_type req.body = data if params: qs = urllib.urlencode(params) environ['QUERY_STRING'] = qs return req
def _data_request(self, path, data, content_type='application/json', method='POST', params=None, user=DEFAULT_USER, tenant=DEFAULT_TENANT): if params is None: params = {} environ = self._environ(path) environ['REQUEST_METHOD'] = method req = wsgi.Request(environ) req.context = utils.dummy_context(user, tenant, is_admin=self.is_admin) self.context = req.context req.content_type = content_type req.body = data if params: qs = urllib.parse.urlencode(params) environ['QUERY_STRING'] = qs return req
def test_fault_call(self, mock_trace): mock_trace.return_value = "test trace" fault_wrapper = fault.FaultWrapper(None) exception = exceptions.PackageClassLoadError("test") exception.message = "Unable to load class 'test' from package" test_fault = fault.Fault(fault_wrapper._error(exception)) environ = { 'SERVER_NAME': 'server.test', 'SERVER_PORT': '8082', 'SERVER_PROTOCOL': 'http', 'SCRIPT_NAME': '/', 'PATH_INFO': '/', 'wsgi.url_scheme': 'http', 'QUERY_STRING': '', 'CONTENT_TYPE': 'application/json', 'REQUEST_METHOD': 'HEAD' } req = wsgi.Request(environ) response = jsonutils.loads(test_fault(req).body) self.assertEqual(response['code'], 400)
def _simple_request(self, path, params=None, method='GET', user=DEFAULT_USER, tenant=DEFAULT_TENANT): """Returns a request with a fake but valid-looking context Returns a request with a fake but valid-looking context and sets the request environment variables. If `params` is given, it should be a dictionary or sequence of tuples. """ environ = self._environ(path) environ['REQUEST_METHOD'] = method if params: qs = urllib.parse.urlencode(params) environ['QUERY_STRING'] = qs req = wsgi.Request(environ) req.context = utils.dummy_context(user, tenant, is_admin=self.is_admin) self.context = req.context return req
def test_best_match_content_type_with_multi_part_path(self, mock_path): request = wsgi.Request({}) supported_content_types = ['application/baz'] result = request.best_match_content_type(None, supported_content_types) self.assertEqual('application/baz', result)