示例#1
0
 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,
     }
示例#2
0
 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,
     }
示例#3
0
 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,
     }
示例#4
0
 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,
     }
示例#5
0
 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,
     }
示例#6
0
 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,
     )
示例#7
0
 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
示例#8
0
    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")
示例#10
0
 def handler(self, restrictions) -> Response:
     assert restrictions == {"allow": "*", "deny": None}
     return Response("x")
示例#11
0
 def list(self, restrictions=None):  # pylint: disable=unused-argument
     return Response({"message": f"Hello, {self.request.user.username} !"})
示例#12
0
 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
示例#13
0
 def test_method(self):
     return Response({"message": "x"})
示例#14
0
 def test_method(self):
     return Response("OK")
示例#15
0
 def get(self):
     return Response({"message": "HelloWorld"})