Esempio n. 1
0
    def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
        req = args[-1]  # TODO : Check
        # TODO : move this code to check_json
        # same idea as in : https://bottlepy.org/docs/dev/_modules/bottle.html#BaseRequest.json
        if req.content_type in ("application/json", "application/json-rpc"):
            try:
                json_body = req.json_body
            # TODO - G.M - 2019-06-06 -  raise exception if not correct ,
            # return 400 if uncorrect instead ?
            except Exception:
                json_body = {}

        else:
            json_body = {}

        forms_parameters = {}
        files_parameters = {}
        for name, item in req.POST.items():
            if isinstance(item, cgi.FieldStorage):
                files_parameters[name] = item
            else:
                forms_parameters[name] = item

        return RequestParameters(
            path_parameters=req.matchdict,
            query_parameters=req.GET,
            body_parameters=json_body,
            form_parameters=req.POST,
            header_parameters=LowercaseKeysDict([
                (k.lower(), v) for k, v in req.headers.items()
            ]),
            files_parameters=files_parameters,
        )
Esempio n. 2
0
    def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
        from flask import request

        return RequestParameters(
            path_parameters=request.view_args,
            query_parameters=request.args,  # TODO: Check
            body_parameters=request.get_json(),  # TODO: Check
            form_parameters=request.form,
            header_parameters=LowercaseKeysDict(
                [(k.lower(), v) for k, v in request.headers.items()]
            ),
            files_parameters=request.files,
        )
Esempio n. 3
0
    def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
        path_parameters = dict(bottle.request.url_args)
        query_parameters = MultiDict(bottle.request.query.allitems())
        body_parameters = dict(bottle.request.json or {})
        form_parameters = MultiDict(bottle.request.forms.allitems())
        header_parameters = LowercaseKeysDict(
            [(k.lower(), v) for k, v in bottle.request.headers.items()]
        )
        files_parameters = dict(bottle.request.files)

        return RequestParameters(
            path_parameters=path_parameters,
            query_parameters=query_parameters,
            body_parameters=body_parameters,
            form_parameters=form_parameters,
            header_parameters=header_parameters,
            files_parameters=files_parameters,
        )
Esempio n. 4
0
 def test_unit__get__ok__nominal_case(self):
     lowercase_dict = LowercaseKeysDict([("foo", "bar")])
     assert "bar" == lowercase_dict.get("foo")
     assert "bar" == lowercase_dict.get("FOO")
Esempio n. 5
0
 def header_parameters(self) -> LowercaseKeysDict:
     # NOTE BS 2019-01-21: headers can be read as lowercase
     return LowercaseKeysDict([(k.lower(), v)
                               for k, v in self._request.headers.items()])
Esempio n. 6
0
    def test_unit__set__error__refuse_key(self):
        lowercase_dict = LowercaseKeysDict()

        with pytest.raises(NotLowercaseCaseException):
            lowercase_dict.setdefault("FOO", "bar")
Esempio n. 7
0
    def test_unit__update__error__refuse_key(self):
        lowercase_dict = LowercaseKeysDict()

        with pytest.raises(NotLowercaseCaseException):
            lowercase_dict.update({"FOO": "bar"})
Esempio n. 8
0
 def test_unit__create__error__refuse_key(self):
     with pytest.raises(NotLowercaseCaseException):
         LowercaseKeysDict([("FOO", "bar")])
Esempio n. 9
0
 def test_unit__create__ok__nominal_case(self):
     lowercase_dict = LowercaseKeysDict([("foo", "bar")])
     assert {"foo": "bar"} == lowercase_dict
Esempio n. 10
0
 def test_unit__del__ok__nominal_case(self):
     lowercase_dict = LowercaseKeysDict([("foo", "bar")])
     del lowercase_dict["FOO"]
Esempio n. 11
0
 def test_unit__in__ok__nominal_case(self):
     lowercase_dict = LowercaseKeysDict([("foo", "bar")])
     assert "foo" in lowercase_dict
     assert "FOO" in lowercase_dict
Esempio n. 12
0
 def test_unit__by_key__ok__nominal_case(self):
     lowercase_dict = LowercaseKeysDict([("foo", "bar")])
     assert "bar" == lowercase_dict["foo"]
     assert "bar" == lowercase_dict["FOO"]