def testBuildRequest_DecodeError(self): """Test trying to build request that causes a decode error.""" self.Reinitialize(urllib.urlencode((('integer_field', '10'), ('integer_field', '20'), )), content_type=self.content_type) url_encoded_mapper = service_handlers.URLEncodedRPCMapper() self.assertRaises(service_handlers.RequestError, url_encoded_mapper.build_request, self.service_handler, Service.method1.remote.request_type)
def testBuildRequest_Prefix(self): """Test building request with parameter prefix.""" self.Reinitialize(urllib.urlencode([('prefix_integer_field', '10'), ('prefix_string_field', 'a string'), ('prefix_enum_field', 'VAL1'), ]), self.content_type) url_encoded_mapper = service_handlers.URLEncodedRPCMapper( parameter_prefix='prefix_') request = url_encoded_mapper.build_request(self.service_handler, Request1) self.assertEquals(10, request.integer_field) self.assertEquals('a string', request.string_field) self.assertEquals(Enum1.VAL1, request.enum_field)
def testBuildResponse_Prefix(self): """Test building a response with parameter prefix.""" response = Response1() response.integer_field = 10 response.string_field = u'a string' response.enum_field = Enum1.VAL3 url_encoded_mapper = service_handlers.URLEncodedRPCMapper( parameter_prefix='prefix_') url_encoded_mapper.build_response(self.service_handler, response) self.assertEquals('application/x-www-form-urlencoded', self.response.headers['content-type']) self.assertEquals(cgi.parse_qs(self.response.out.getvalue(), True, True), {'prefix_integer_field': ['10'], 'prefix_string_field': [u'a string'], 'prefix_enum_field': ['VAL3'], })