1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
import json
class FakeResponse:
def __init__(self, status=200, body={}, content_type="application/json"):
self.status = status
self.body = body
self.content_type = content_type
async def json(self):
return json.dumps(self.body)
async def release(self):
pass
def mockreturn(
return_status=None, return_body={}, content_type="application/json", exception=None
):
async def mocked(path, data, headers):
if exception:
raise exception
else:
return FakeResponse(
status=return_status, body=return_body, content_type=content_type
)
return mocked
|