Ejemplo n.º 1
0
def create_user_view(request):
    serializer = UserCreateSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return Response({'message': 'ok'})
    else:
        return Response({'messgae': 'error'})
Ejemplo n.º 2
0
 def post(self, request):
     serializer = UserCreateSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
 def test_user_create(self, mock_create, mock_model_create):
     uid = "test_uid"
     serializer = UserCreateSerializer(data=self.data)
     # anonymous object creation
     firebase_user = type("", (object, ), {"uid": uid})()
     model_user = type("", (object, ), {"firebase_uid": uid})()
     mock_create.return_value = firebase_user
     mock_model_create.return_value = model_user
     self.assertTrue(serializer.is_valid())
     user = serializer.save()
     self.assertEqual(user.firebase_uid, uid)
     mock_create.assert_called_once_with(email="*****@*****.**")
     mock_model_create.assert_called_once()
Ejemplo n.º 4
0
def registration(request):
    serializer = UserCreateSerializer(data=request.data)
    if not serializer.is_valid():
        return response.Response(serializer.errors,
                                 status.HTTP_400_BAD_REQUEST)
    user = serializer.save()
    refresh = RefreshToken.for_user(user)
    res = {
        "refresh": str(refresh),
        "access": str(refresh.access_token),
        "username": user.username
    }
    return response.Response(res, status.HTTP_201_CREATED)
Ejemplo n.º 5
0
 def post(self, request):
     serializer = UserCreateSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.save()  # UserCreateSerializer.create 호출
     return Response(data=user.pk, status=HTTP_201_CREATED)