增加逻辑判断用户名重复的问题

This commit is contained in:
virusdefender 2015-08-14 10:21:50 +08:00
parent f3be10161f
commit e84039eea1
2 changed files with 8 additions and 2 deletions

View File

@ -145,10 +145,10 @@ class UserChangePasswordAPITest(APITestCase):
self.assertEqual(response.data, {"code": 0, "data": u"用户密码修改成功!"})
class UserAPITest(APITestCase):
class UserAdminAPITest(APITestCase):
def setUp(self):
self.client = APIClient()
self.url = reverse("user_list_api")
self.url = reverse("user_admin_api")
user = User.objects.create(username="testx", real_name="xx", admin_type=SUPER_ADMIN)
user.set_password("testxx")
user.save()

View File

@ -135,6 +135,12 @@ class UserAdminAPIView(APIView):
user = User.objects.get(id=data["id"])
except User.DoesNotExist:
return error_response(u"该用户不存在!")
try:
user = User.objects.get(username=data["username"])
if user.id != data["id"]:
return error_response(u"昵称已经存在")
except User.DoesNotExist:
pass
user.username = data["username"]
user.real_name = data["real_name"]
user.email = data["email"]