def make_request(self, method, path, params=None, data=None,
authenticated=True, auth_type='Basic', headers={},
token=testing.ADMIN_TOKEN, accept='application/json'):
settings = {}
headers = headers.copy()
settings['headers'] = headers
if accept is not None:
settings['headers']['ACCEPT'] = accept
if authenticated and token is not None:
settings['headers']['AUTHORIZATION'] = '{} {}'.format(
auth_type, token)
settings['params'] = params
settings['data'] = data
async with aiohttp.ClientSession(loop=self.loop) as session:
operation = getattr(session, method.lower(), None)
async with operation(self.server.make_url(path), **settings) as resp:
try:
value = await resp.json()
status = resp.status
except: # noqa
value = await resp.read()
status = resp.status
return value, status, resp.headers
评论列表
文章目录