def test_account_8(self): Account.objects.filter(oj_username='******', oj_name='wust').delete() request_data = { 'oj_name': 'wust', 'oj_username': '******', 'oj_password': '******' } serializer = AccountSerializer(data=request_data) self.assertTrue(serializer.is_valid(), serializer.errors) self.assertTrue(serializer.save())
def post(self, request, *args, **kwargs): if request.user is None or request.user.is_authenticated is False or request.user.is_admin is False: return Response(res_format('Permission Denied', status=Message.ERROR), status=status.HTTP_200_OK) serializer = AccountSerializer(data=request.data) if serializer.is_valid(): if serializer.save(): update_language_task.delay( serializer.validated_data['oj_name']) return Response(res_format('success'), status=status.HTTP_200_OK) else: return Response(res_format('error', status=Message.ERROR), status=status.HTTP_500_INTERNAL_SERVER_ERROR) else: return Response(res_format(serializer.errors, status=Message.ERROR), status=status.HTTP_400_BAD_REQUEST)
def post(self, request, *args, **kwargs): if request.user is None or request.user.is_authenticated is False or request.user.is_admin is False: return Response(res_format('Permission Denied', status=Message.ERROR), status=status.HTTP_200_OK) serializer = AccountSerializer(data=request.data) if serializer.is_valid(): if serializer.save(): return Response(res_format('operation success', status=Message.SUCCESS), status=status.HTTP_200_OK) else: return Response(res_format('operation failed', status=Message.ERROR), status=status.HTTP_500_INTERNAL_SERVER_ERROR) else: return Response(res_format(serializer.errors, status=Message.ERROR), status=status.HTTP_400_BAD_REQUEST)
def test_account_7(self): request_data = {'remote_oj': 'wust', 'username': '******', 'password': '******'} serializer = AccountSerializer(data=request_data) self.assertTrue(serializer.is_valid(), serializer.errors) self.assertTrue(serializer.save())