コード例 #1
0
    def test_serializer_case_username_not_exist_with_force_create(self):
        serializer = AuthTokenSerializer(data={
            'username': '******',
            'force_user_creation': True
        })
        self.assertTrue(serializer.is_valid())

        UserModel = backends.get_user_model()
        user_created = serializer.validated_data['user']
        self.assertEqual('dummy-username',
                         getattr(user_created, UserModel.USERNAME_FIELD))
コード例 #2
0
 def test_serializer_case_success_ensure_user(self):
     user = UserFactory()
     serializer = AuthTokenSerializer(data={'username': user.username})
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.validated_data['user'], user)
コード例 #3
0
 def test_serializer_case_username_not_exist(self):
     serializer = AuthTokenSerializer(data={'username': '******'})
     with self.assertRaises(serializers.ValidationError):
         serializer.is_valid(raise_exception=True)
コード例 #4
0
 def test_serializer_case_username_required(self):
     serializer = AuthTokenSerializer(data={})
     self.assertFalse(serializer.is_valid())