def test_response_body_passes_through_when_string(self): response = Response("xxx", headers={"xx": "xx"}, status_code=666) assert response.to_dict() == { "body": "xxx", "headers": { "xx": "xx" }, "statusCode": 666, "isBase64Encoded": False, }
def test_text_plain_header_added_when_string_without_headers(self): response = Response("xxx", status_code=666) assert response.to_dict() == { "body": "xxx", "headers": { "Content-Type": "text/plain" }, "statusCode": 666, "isBase64Encoded": False, }
def test_application_json_header_added_when_dict_without_headers(self): response = Response({"message": "xxx"}, status_code=666) assert response.to_dict() == { "body": '{"message":"xxx"}', "headers": { "Content-Type": "application/json" }, "statusCode": 666, "isBase64Encoded": False, }
def test_response_body_is_json_dump_when_dict(self): response = Response({"message": "xxx"}, headers={"xx": "xx"}, status_code=666) assert response.to_dict() == { "body": '{"message":"xxx"}', "headers": { "xx": "xx" }, "statusCode": 666, "isBase64Encoded": False, }
def test_response_body_passes_through_when_base64(self): data = b64encode(b"xxx").decode("utf-8") response = Response(data, headers={"xx": "xx"}, status_code=666, base64_encoded=True) assert response.to_dict() == { "body": data, "headers": { "xx": "xx" }, "statusCode": 666, "isBase64Encoded": True, }
def get_response(self, request_id: str) -> Response: """ Creates a proper standarised Response for Errors. """ return Response( {"message": self.message, "request_id": request_id}, status_code=self.status_code, )
def test___init__2(self): resp = Response({"message": "xxx"}, headers={"xx": "xx"}, status_code=666) assert isinstance(resp.body, dict) assert resp.body == {"message": "xxx"} assert resp.headers == {"xx": "xx"} assert resp.status_code == 666 assert not resp.is_base64
def __call__(self) -> Response: if self.method == "OPTIONS": return Response("", headers=self.resp_headers(), status_code=HTTPStatus.NO_CONTENT) resp = super().__call__() if resp.status_code >= 400 and ALLOW_ORIGIN_HEADER not in resp.headers: resp.headers.update(self.resp_headers()) return resp
def garbage(self, restrictions) -> Response: # pylint: disable=unused-argument return Response("ok")
def handler(self, restrictions) -> Response: assert restrictions == {"allow": "*", "deny": None} return Response("x")
def list(self, restrictions=None): # pylint: disable=unused-argument return Response({"message": f"Hello, {self.request.user.username} !"})
def test___init__(self): resp = Response({}) assert isinstance(resp.body, dict) assert resp.headers == {"Content-Type": "application/json"} assert resp.status_code == 200 assert not resp.is_base64
def test_method(self): return Response({"message": "x"})
def test_method(self): return Response("OK")
def get(self): return Response({"message": "HelloWorld"})