Exemple #1
0
 def test_update_user(self):
     data = UserSerializer(self.user).data
     data.update({
         "username": "******",
     })
     response = self.client.put(reverse('DetailUser', args=[self.user.id]), data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemple #2
0
def signup(request: Request) -> Response:
    register_serializer = UserRegisterSerializer(data=request.data)
    if not register_serializer.is_valid():
        return Response(register_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    if User.objects.filter(userprofile__student_id=register_serializer.validated_data['student_id']):
        # 判断注册的用户是微信小程序用户:姓名和学号与数据库中相同,且数据库中密码为空
        # 如果满足条件,则将找到的用户的信息更新,然后返回 200
        origin_wechat_user = User.objects.filter(
            userprofile__student_id=register_serializer.validated_data['student_id'],
            first_name=register_serializer.validated_data['first_name'],
            password='')
        if origin_wechat_user:
            u = origin_wechat_user[0]
            user_serializer = UserSerializer(u)
            user_serializer.update(u, register_serializer.validated_data)
            return Response(user_serializer.data, status=status.HTTP_200_OK)
        else:
            return Response(data={"student_id": "学号已存在"}, status=status.HTTP_400_BAD_REQUEST)
    u = register_serializer.save()
    user_serializer = UserSerializer(u)
    return Response(user_serializer.data, status=status.HTTP_201_CREATED)
Exemple #3
0
 def test_update_user(self):
     data = UserSerializer(self.user).data
     data.update({"username": "******"})
     response = self.client.put(reverse("DetailUser", args=[self.user.id]), data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)