def test_post(self): with open('httputil.py', 'rb') as fi: data = fi.read() with httputil.download(self.target + '/post/postmatch', data=data).makefile() as f: body = f.read() self.assertEqual(body, str(len(data)).encode(httputil.ENCODING))
def test_post_file(self): with open('httputil.py', 'rb') as fi: with httputil.download(self.target + '/post/postmatch', data=fi).makefile() as f: body = f.read() with open('httputil.py', 'rb') as fi: data = fi.read() self.assertEqual(body, str(len(data)).encode(httputil.ENCODING))
def test_getfile(self): with httputil.download(self.target + '/urlmatch').makefile() as f: body = f.read() self.assertEqual( json.loads(body.decode('utf-8')), { 'page': 'main', 'path': 'urlmatch', 'count': 0, 'match': {}, 'param': {'main param': 1} })
def test_getfile(self): with httputil.download(self.target + '/urlmatch').makefile() as f: body = f.read() self.assertEqual( json.loads(body.decode('utf-8')), { 'page': 'main', 'path': 'urlmatch', 'count': 0, 'match': {}, 'param': { 'main param': 1 } })
def download(url): with closing(httputil.download(url)) as resp: return resp.readbody()