コード例 #1
0
 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, '*****@*****.**')
コード例 #2
0
 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')
コード例 #3
0
    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"})
コード例 #4
0
ファイル: views.py プロジェクト: aamishbaloch/code_sample
 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()
コード例 #5
0
 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)