def test_get_request_data_invalid(self): data = '{a:b}' post = self.factory.post('/', data, content_type='application/json') request = Request(post, parsers=[JSONParser()]) with pytest.raises(ParseError): get_request_data(request)
def post(self, request): serializer = self.get_serializer(data=get_request_data(request)) if serializer.is_valid(): user = serializer.object.get('user') or request.user token = serializer.object.get('token') data = dict() data["token"] = token data["expire"] = api_settings.JWT_EXPIRATION_DELTA.total_seconds() return Response(data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): serializer = self.get_serializer( data=get_request_data(request) ) if serializer.is_valid(): user = serializer.object.get('user') or request.user token = serializer.object.get('token') data = dict() data["token"] = token data["expire"] = api_settings.JWT_EXPIRATION_DELTA.total_seconds() return Response(data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def test_get_request_data_empty(self): data = '' post = self.factory.post('/', data, content_type='application/json') request = Request(post, parsers=[JSONParser()]) assert get_request_data(request) == {}