Пример #1
0
 def serializer_create_returns_the_validated_data(self):
     good_user = {
         'username': '******',
         'email': '*****@*****.**',
         'email2': '*****@*****.**',
         'password': '******',
     }
     user = UserCreateSerializer.create(validated_data=good_user)
     self.assertEqual(user, good_user)
Пример #2
0
    def post(self, request, *args, **kwargs):
        fields = {
            'email': request.data.get('email'),
            'password': request.data.get('password'),
            'last_name': request.data.get('last_name'),
            'first_name': request.data.get('first_name'),
        }

        serializer = UserCreateSerializer(data=fields)

        serializer.is_valid(raise_exception=True)

        user = serializer.create(serializer.validated_data)
        return Response(UserSerializer(user).data,
                        status=status.HTTP_201_CREATED)