Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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) == {}