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
def matches_content_type(self, request: Request) -> bool: return request.declares_json()
def test_request_declares_json(headers, expected_result): request = Request("GET", b"/", headers) assert request.declares_json() is expected_result
def test_request_declares_json(headers, expected_result): request = Request('GET', b'/', headers) assert request.declares_json() is expected_result