def test_body(self): # simulate a problem I had with a request with curl r = Request() r.method = 'GET' r.body = "" r.set_headers({ 'PATTERN': "/", 'x-forwarded-for': "127.0.0.1", 'URI': "/", 'accept': "*/*", 'user-agent': "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5", 'host': "localhost", 'VERSION': "HTTP/1.1", 'PATH': "/", 'METHOD': "GET", 'authorization': "Basic SOME_HASH_THAT_DOES_NOT_MATTER=" }) self.assertEqual("", r.body) r = Request() r.method = 'POST' r.set_header('content-type', "application/x-www-form-urlencoded") r.body = "foo=bar&che=baz&foo=che" body_r = {'foo': ['bar', 'che'], 'che': 'baz'} self.assertEqual(body_r, r.body_kwargs) r.body = None #del(r._body_kwargs) body_r = {} self.assertEqual(body_r, r.body_kwargs) r.set_header('content-type', "application/json") r.body = '{"person":{"name":"bob"}}' #del(r._body_kwargs) body_r = {'person': {"name":"bob"}} self.assertEqual(body_r, r.body_kwargs) r.body = '' #del(r._body_kwargs) body_r = '' self.assertEqual(body_r, r.body) r.headers = {} body = '{"person":{"name":"bob"}}' r.body = body self.assertEqual(body, r.body) r.method = 'GET' r.set_header('content-type', "application/json") r.body = None self.assertEqual(None, r.body)
def test_body(self): # simulate a problem I had with a request with curl r = Request() r.method = 'GET' r.body = "" r.set_headers({ 'PATTERN': "/", 'x-forwarded-for': "127.0.0.1", 'URI': "/", 'accept': "*/*", 'user-agent': "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5", 'host': "localhost", 'VERSION': "HTTP/1.1", 'PATH': "/", 'METHOD': "GET", 'authorization': "Basic SOME_HASH_THAT_DOES_NOT_MATTER=" }) self.assertEqual("", r.body) r = Request() r.method = 'POST' r.set_header('content-type', "application/x-www-form-urlencoded") r.body = "foo=bar&che=baz&foo=che" body_r = {'foo': ['bar', 'che'], 'che': 'baz'} self.assertEqual(body_r, r.body_kwargs) r.body = None #del(r._body_kwargs) body_r = {} self.assertEqual(body_r, r.body_kwargs) r.set_header('content-type', "application/json") r.body = '{"person":{"name":"bob"}}' #del(r._body_kwargs) body_r = {'person': {"name": "bob"}} self.assertEqual(body_r, r.body_kwargs) r.body = '' #del(r._body_kwargs) body_r = '' self.assertEqual(body_r, r.body) r.headers = {} body = '{"person":{"name":"bob"}}' r.body = body self.assertEqual(body, r.body) r.method = 'GET' r.set_header('content-type', "application/json") r.body = None self.assertEqual(None, r.body)
def get_http_instances(self, path="", method="GET"): req = Request() req.method = method req.path = path res = Response() return req, res