diff --git a/account/serializers.py b/account/serializers.py index d82b36db..358ced71 100644 --- a/account/serializers.py +++ b/account/serializers.py @@ -41,6 +41,6 @@ class EditUserSerializer(serializers.Serializer): id = serializers.IntegerField() username = serializers.CharField(max_length=30) real_name = serializers.CharField(max_length=30) - password = serializers.CharField(max_length=30, min_length=6, required=True) + password = serializers.CharField(max_length=30, min_length=6, required=False, default=None) email = serializers.EmailField(max_length=254) admin_type = serializers.IntegerField(default=0) diff --git a/account/tests.py b/account/tests.py index 41158294..ca69832b 100644 --- a/account/tests.py +++ b/account/tests.py @@ -4,6 +4,7 @@ import json from django.core.urlresolvers import reverse from django.test import TestCase, Client from django.http import HttpResponse +from django.contrib import auth from rest_framework.test import APITestCase, APIClient from rest_framework.views import APIView @@ -194,11 +195,18 @@ class UserAdminAPITest(APITestCase): self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"}) def test_success_user_edit_not_password(self): - data = {"id": 1, "username": "test0", "real_name": "test00", "password": "aaaaaa", + data = {"id": 1, "username": "test0", "real_name": "test00", "email": "60@qq.com", "admin_type": "2"} response = self.client.put(self.url, data=data) self.assertEqual(response.data["code"], 0) + def test_success_user_edit_change_password(self): + data = {"id": 1, "username": "test0", "real_name": "test00", "password": "111111", + "email": "60@qq.com", "admin_type": "2"} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data["code"], 0) + self.assertIsNotNone(auth.authenticate(username="test0", password="111111")) + @login_required def login_required_FBV_test_without_args(request):