Beispiel #1
0
 def test_flagging_unflagged_object(self):
     post = self.post
     data = self.data.copy()
     data['model_id'] = post.id
     data.pop('reason')
     response = process_flagging_request(user=self.user_1,
                                         model_obj=self.post,
                                         data=data)
     response_data = {
         'status': 1,
         'msg': [f'This content has not been flagged by the user']
     }
     self.assertDictEqual(response, response_data)
Beispiel #2
0
 def test_flagging_flagged_object(self):
     data = self.data.copy()
     post = self.post
     data['model_id'] = post.id
     self.set_flag(post)
     response = process_flagging_request(user=self.user_1,
                                         model_obj=self.post,
                                         data=data)
     response_data = {
         'status': 1,
         'msg': [f'This content has already been flagged by the user']
     }
     self.assertDictEqual(response, response_data)
Beispiel #3
0
    def post(self, request, *args, **kwargs):
        self.validate(self.request)
        response = process_flagging_request(user=request.user,
                                            model_obj=self.model_obj,
                                            data=self.data)
        detail = {'detail': response['msg']}

        if response['status']:  # 1 indicates bad request
            return Response(status=status.HTTP_400_BAD_REQUEST, data=detail)

        flag = Flag.objects.get_flag(self.model_obj)
        serializer = FlagSerializer(instance=flag,
                                    context=self._get_serializer_context())
        return Response(serializer.data, status=status.HTTP_200_OK)
    def test_unflagging_successfully(self):
        post = self.post
        self.set_flag(model_obj=post)
        data = self.data.copy()
        data['model_id'] = post.id
        data.pop('reason')
        response = process_flagging_request(user=self.user_1,
                                            model_obj=post,
                                            data=data)
        response_data = {
            'status': 0,
            'msg': 'The content has been unflagged successfully.'
        }

        self.assertDictEqual(response, response_data)
 def test_flagging_successfully(self):
     data = self.data.copy()
     post = self.post
     data['model_id'] = post.id
     response = process_flagging_request(user=self.user_1,
                                         model_obj=post,
                                         data=data)
     response_data = {
         'status':
         0,
         'flag':
         1,
         'msg':
         'The content has been flagged successfully. A moderator will review it shortly.'
     }
     self.assertDictEqual(response, response_data)
Beispiel #6
0
 def post(self, request, *args, **kwargs):
     response = process_flagging_request(user=request.user,
                                         model_obj=self.model_obj,
                                         data=self.data)
     return JsonResponse(response)