def _request(method, path, type, **kwargs):
url = 'http://localhost:8000%s' % path
res = method(url, **kwargs)
res.raise_for_status()
if type == 'html':
assert 'text/html' in res.headers['Content-Type']
doc = bs4.BeautifulSoup(res.text, 'html5lib')
elif type == 'text':
assert 'text/plain' in res.headers['Content-Type']
doc = res.text
elif type == 'json':
assert ('application/json' in res.headers['Content-Type'] or
'text/plain' in res.headers['Content-Type'])
doc = ujson.loads(res.text)
else:
assert False, type
return (res, doc)
评论列表
文章目录