当前位置: 首页>>代码示例>>Python>>正文


Python UserFactory.build方法代码示例

本文整理汇总了Python中user_management.models.tests.factories.UserFactory.build方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.build方法的具体用法?Python UserFactory.build怎么用?Python UserFactory.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user_management.models.tests.factories.UserFactory的用法示例。


在下文中一共展示了UserFactory.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_deserialize

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
 def test_deserialize(self):
     user = UserFactory.build()
     data = {
         'name': 'New Name',
     }
     serializer = serializers.ProfileSerializer(user, data=data)
     self.assertTrue(serializer.is_valid())
开发者ID:pombredanne,项目名称:django-user-management,代码行数:9,代码来源:test_serializers.py

示例2: test_get

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_get(self):
        user = UserFactory.build(avatar=SIMPLE_PNG)

        request = self.create_request(user=user)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['avatar'], SIMPLE_PNG.url)
开发者ID:lowks,项目名称:django-user-management,代码行数:10,代码来源:test_views.py

示例3: test_get_no_avatar

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_get_no_avatar(self):
        user = UserFactory.build()

        request = self.create_request(user=user)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['avatar'], None)
开发者ID:lowks,项目名称:django-user-management,代码行数:10,代码来源:test_views.py

示例4: test_post_invalid_user

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_post_invalid_user(self):
        """Assert inexisting user verification return a bad request."""
        user = UserFactory.build()
        token = user.generate_validation_token()

        request = self.create_request('post')
        view = self.view_class.as_view()
        response = view(request, token=token)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
开发者ID:mdlx,项目名称:django-user-management,代码行数:11,代码来源:test_views.py

示例5: test_serialize

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_serialize(self):
        user = UserFactory.build()
        serializer = serializers.ProfileSerializer(user)

        expected = {
            'name': user.name,
            'email': user.email,
            'date_joined': user.date_joined,
        }
        self.assertEqual(serializer.data, expected)
开发者ID:pombredanne,项目名称:django-user-management,代码行数:12,代码来源:test_serializers.py

示例6: test_get

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_get(self):
        user = UserFactory.build()

        request = self.create_request(user=user)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected = self.expected_data(user)
        self.assertEqual(response.data, expected)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:12,代码来源:test_views.py

示例7: test_deserialize_invalid_new_password

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_deserialize_invalid_new_password(self):
        new_password = '2Short'
        user = UserFactory.build()

        serializer = serializers.PasswordResetSerializer(user, data={
            'new_password': new_password,
            'new_password2': new_password,
        })
        self.assertFalse(serializer.is_valid())
        self.assertIn('new_password', serializer.errors)
开发者ID:mdlx,项目名称:django-user-management,代码行数:12,代码来源:test_serializers.py

示例8: test_full_stack_wrong_url

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_full_stack_wrong_url(self):
        """Integration test to check a nonexistent email returns a bad request."""
        user = UserFactory.build()
        token = user.generate_validation_token()

        view_name = 'user_management_api:verify_user'
        url = reverse(view_name, kwargs={'token': token})
        response = self.client.post(url)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        self.assertTrue(hasattr(response, 'accepted_renderer'))
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:13,代码来源:test_views.py

示例9: test_deserialize_invalid_old_password

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_deserialize_invalid_old_password(self):
        old_password = 'old_password'
        new_password = 'new_password'

        user = UserFactory.build(password=old_password)

        serializer = serializers.PasswordChangeSerializer(user, data={
            'old_password': 'invalid_password',
            'new_password': new_password,
            'new_password2': new_password,
        })
        self.assertFalse(serializer.is_valid())
        self.assertIn('old_password', serializer.errors)
开发者ID:pombredanne,项目名称:django-user-management,代码行数:15,代码来源:test_serializers.py

示例10: test_deserialize_invalid_new_password

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_deserialize_invalid_new_password(self):
        old_password = 'old_password'
        new_password = '2short'

        user = UserFactory.build(password=old_password)

        serializer = serializers.PasswordChangeSerializer(user, data={
            'old_password': old_password,
            'new_password': new_password,
            'new_password2': new_password,
        })
        self.assertFalse(serializer.is_valid())
        self.assertIn('new_password', serializer.errors)
        self.assertTrue(serializer.object.check_password(old_password))
开发者ID:pombredanne,项目名称:django-user-management,代码行数:16,代码来源:test_serializers.py

示例11: test_get_resize_width

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_get_resize_width(self):
        user = UserFactory.build(avatar=SIMPLE_PNG)

        data = {
            'width': 10,
        }
        request = self.create_request(user=user, data=data)
        view = self.view_class.as_view()
        expected_url = 'mocked-url'
        with patch('django.core.files.storage.Storage.url') as mocked_url:
            mocked_url.return_value = expected_url
            response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertNotEqual(response.data['avatar'], expected_url)
开发者ID:lowks,项目名称:django-user-management,代码行数:16,代码来源:test_views.py

示例12: test_deserialize_invalid_old_password

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_deserialize_invalid_old_password(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'

        user = UserFactory.build(password=old_password)

        serializer = serializers.PasswordChangeSerializer()
        data = {
            'old_password': 'invalid_password',
            'new_password': new_password,
            'new_password2': new_password,
        }
        with self.assertRaises(ValidationError):
            serializer.update(user, data)
开发者ID:mdlx,项目名称:django-user-management,代码行数:16,代码来源:test_serializers.py

示例13: test_patch

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
    def test_patch(self):
        user = UserFactory.build(is_staff=True)
        other_user = UserFactory.create()
        data = {'avatar': SIMPLE_PNG}

        request = APIRequestFactory().patch('/', data=data)
        request.user = user
        force_authenticate(request, user)

        view = self.view_class.as_view()
        with patch('django.core.files.storage.Storage.url') as mocked_url:
            mocked_url.return_value = 'mocked-url'
            response = view(request, pk=other_user.pk)
        self.assertEqual(response.status_code, 200)
        SIMPLE_PNG.seek(0)
        user = User.objects.get(pk=other_user.pk)
        self.assertEqual(user.avatar.read(), SIMPLE_PNG.read())
开发者ID:lowks,项目名称:django-user-management,代码行数:19,代码来源:test_views.py

示例14: setUp

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
 def setUp(self):
     self.user = UserFactory.build()
     self.other_user = UserFactory.build(avatar=SIMPLE_PNG)
开发者ID:lowks,项目名称:django-user-management,代码行数:5,代码来源:test_views.py

示例15: test_deserialize

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import build [as 别名]
 def test_deserialize(self):
     user = UserFactory.build()
     data = {'avatar': ''}
     serializer = serializers.AvatarSerializer(user, data=data)
     self.assertTrue(serializer.is_valid())
开发者ID:lowks,项目名称:django-user-management,代码行数:7,代码来源:test_serializers.py


注:本文中的user_management.models.tests.factories.UserFactory.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。