def test_partial_update(self): serializer = UserSerializer(self.user, data={'email': '*****@*****.**'}, partial=True) self.assertTrue(serializer.is_valid()) serializer.save() self.assertEqual(self.user.email, '*****@*****.**')
def test_serializer_updates_profile(self): serializer = UserSerializer(self.user, data={ 'email': '*****@*****.**', 'about': 'my about', 'pic': 'https://my.pic.com/my.png', 'password': '******' }) self.assertTrue(serializer.is_valid()) serializer.save() self.assertEqual(self.user.profile.pic, 'https://my.pic.com/my.png') self.assertEqual(self.user.profile.about, 'my about')
def post(self, request): user_serializer = UserSerializer(data=request.data) user_serializer.is_valid(raise_exception=True) team = user_serializer.get_team() user = user_serializer.save() bind_user_to_team(user, team) return Response({"result": "success"})
def post(self, request): if not User.is_exists(request.data['email']): serializer = UserSerializer(data=request.data) if serializer.is_valid(): user = serializer.save() user.generate_code_for_user() return Response(serializer.data, status=status.HTTP_201_CREATED) raise InvalidInputDataException(str(serializer.errors)) raise UserExistsException()
def post(self, request): serializer = UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)