Esempio n. 1
0
    async def get_value(self, request: Request) -> T:
        if request.declares_json(
        ) and request.method not in self._excluded_methods:
            data = await request.json()

            if not data:
                raise MissingBodyError()

            return self.parse_value(data)

        if self.required:
            if not request.has_body():
                raise MissingBodyError()

            raise InvalidRequestBody('Expected JSON payload')

        return None
Esempio n. 2
0
 def matches_content_type(self, request: Request) -> bool:
     return request.declares_json()
Esempio n. 3
0
def test_request_declares_json(headers, expected_result):
    request = Request("GET", b"/", headers)
    assert request.declares_json() is expected_result
Esempio n. 4
0
def test_request_declares_json(headers, expected_result):
    request = Request('GET', b'/', headers)
    assert request.declares_json() is expected_result