def test_account_7(self): request_data = { 'oj_name': 'wust', 'oj_username': '******', 'oj_password': '******' } serializer = AccountSerializer(data=request_data) self.assertFalse(serializer.is_valid(), serializer.errors)
def test_account_6(self): request_data = { 'oj_name': 'hdu', 'oj_username': '******', 'oj_password': '******' } serializer = AccountSerializer(data=request_data) self.assertTrue(serializer.is_valid())
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 get(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) accounts = Account.objects.all().order_by('-id') return Response(res_format( AccountSerializer(accounts, many=True).data))
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())
def test_account_5(self): request_data = {'remote_oj': 'HDU1', 'username': '******', 'password': '******'} serializer = AccountSerializer(data=request_data) self.assertFalse(serializer.is_valid())
def test_account_2(self): request_data = {'remote_oj1': '', 'username2': '', 'password': ''} serializer = AccountSerializer(data=request_data) self.assertFalse(serializer.is_valid())
def test_account_3(self): request_data = {'oj_name': '', 'oj_username': '', 'oj_password1': ''} serializer = AccountSerializer(data=request_data) self.assertFalse(serializer.is_valid())