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


Python UserFactory.create方法代码示例

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


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

示例1: test_put_invalid_token

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_put_invalid_token(self):
        user = UserFactory.create()
        other_user = UserFactory.create()
        token = default_token_generator.make_token(other_user)
        uid = urlsafe_base64_encode(force_bytes(user.pk))

        request = self.create_request('put', auth=False)
        view = self.view_class.as_view()
        response = view(request, uidb64=uid, token=token)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:12,代码来源:test_views.py

示例2: test_post

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post(self):
        """Assert user can sign in"""
        UserFactory.create(email=self.username, password=self.password)

        request = self.create_request('post', auth=False, data=self.data)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(
            response.status_code, status.HTTP_200_OK, msg=response.data)

        # Ensure user has a token now
        token = self.model.objects.get()
        self.assertEqual(response.data['token'], token.key)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:15,代码来源:test_views.py

示例3: test_deserialize_update_email_in_use

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
 def test_deserialize_update_email_in_use(self):
     user = UserFactory.create()
     other_user = UserFactory.create()
     data = {
         'name': "Robert'); DROP TABLE Students;--'",
         'email': other_user.email,
         'password': 'Sup3RSecre7paSSw0rD',
         'password2': 'Sup3RSecre7paSSw0rD',
     }
     serializer = serializers.RegistrationSerializer(user, data=data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer._errors['email'],
         ['That email address has already been registered.'])
开发者ID:pombredanne,项目名称:django-user-management,代码行数:16,代码来源:test_serializers.py

示例4: test_post_rate_limit

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post_rate_limit(self):
        """Ensure the POST requests are rate limited."""
        email = '[email protected]'
        UserFactory.create(email=email)

        data = {'email': email}
        request = self.create_request('post', data=data, auth=False)
        view = self.view_class.as_view()

        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # request is throttled
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:17,代码来源:test_throttling.py

示例5: test_post_user_not_confirmed

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post_user_not_confirmed(self):
        """Assert non active users can not log in."""
        UserFactory.create(email=self.username, password=self.password, is_active=False)

        request = self.create_request('post', auth=False, data=self.data)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(
            response.status_code,
            status.HTTP_400_BAD_REQUEST,
            msg=response.data,
        )
        expected = 'User account is disabled.'
        self.assertIn(expected, response.data['non_field_errors'])
        self.assertNotIn('token', response.data)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:17,代码来源:test_views.py

示例6: test_post

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post(self):
        username = '[email protected]'
        password = 'myepicstrongpassword'
        UserFactory.create(email=username.lower(), password=password)

        data = {'username': username, 'password': password}
        request = self.create_request('post', auth=False, data=data)
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(
            response.status_code, status.HTTP_200_OK, msg=response.data)

        # Ensure user has a token now
        token = self.model.objects.get(user__email=username.lower())
        self.assertEqual(response.data['token'], token.key)
开发者ID:hungtd9,项目名称:django-user-management,代码行数:17,代码来源:test_views.py

示例7: test_post_different_user_logged_in

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post_different_user_logged_in(self):
        """Assert a user can have amny accounts and verify one."""
        user = UserFactory.create()
        other_user = UserFactory.create()
        token = user.generate_validation_token()

        request = self.create_request('post', user=other_user)
        view = self.view_class.as_view()
        response = view(request, token=token)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        updated_user = User.objects.get(pk=user.pk)
        self.assertTrue(updated_user.email_verified)

        logged_in_user = User.objects.get(pk=other_user.pk)
        self.assertFalse(logged_in_user.email_verified)
开发者ID:mdlx,项目名称:django-user-management,代码行数:18,代码来源:test_views.py

示例8: test_duplicate_email

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_duplicate_email(self):
        """Emails should be unique regardless of case."""
        # First create a user with the same email.
        self.data.pop('password2')
        UserFactory.create(**self.data)

        # Just for kicks, lets try changing the email case.
        self.data['email'] = self.data['email'].upper()

        request = self.create_request('post', auth=False, data=self.data)
        response = self.view_class.as_view()(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        self.assertTrue('email' in response.data, msg=response.data)

        self.assertEqual(User.objects.count(), 1)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:18,代码来源:test_views.py

示例9: test_delete_without_avatar

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_delete_without_avatar(self):
        user = UserFactory.create()
        request = self.create_request('delete', user=user)
        view = self.view_class.as_view()
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:9,代码来源:test_views.py

示例10: test_existent_email

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_existent_email(self):
        email = '[email protected]'
        user = UserFactory.create(email=email)
        context = {}
        site = Site.objects.get_current()

        request = self.create_request(
            'post',
            data={'email': email},
            auth=False,
        )
        view = self.view_class.as_view()
        with patch(EMAIL_CONTEXT) as get_context:
            get_context.return_value = context
            with patch(SEND_METHOD) as send_email:
                response = view(request)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        expected = {
            'to': user.email,
            'template_name': 'user_management/password_reset_email.txt',
            'html_template_name': 'user_management/password_reset_email.html',
            'subject': '{} password reset'.format(site.domain),
            'context': context,
            'headers': {},
        }
        send_email.assert_called_once_with(**expected)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:29,代码来源:test_views.py

示例11: test_post_email_already_verified

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
 def test_post_email_already_verified(self):
     """Assert email already verified does not trigger another email."""
     user = UserFactory.create(email_verified=True)
     request = self.create_request('post', auth=False, data={'email': user.email})
     view = self.view_class.as_view()
     response = view(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertIn('email', response.data)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:10,代码来源:test_views.py

示例12: test_options

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_options(self):
        user = UserFactory.create()
        token = default_token_generator.make_token(user)
        uid = urlsafe_base64_encode(force_bytes(user.pk))

        request = self.create_request('options', auth=False)
        view = self.view_class.as_view()
        response = view(request, uidb64=uid, token=token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:11,代码来源:test_views.py

示例13: test_post_verified_email

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post_verified_email(self):
        """Assert verified user cannot verify email."""
        user = UserFactory.create(email_verified=True)
        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_403_FORBIDDEN)
开发者ID:mdlx,项目名称:django-user-management,代码行数:11,代码来源:test_views.py

示例14: test_post_expired_token

# 需要导入模块: from user_management.models.tests.factories import UserFactory [as 别名]
# 或者: from user_management.models.tests.factories.UserFactory import create [as 别名]
    def test_post_expired_token(self):
        """Assert token expires."""
        user = UserFactory.create()
        token = user.generate_validation_token()
        request = self.create_request('post', auth=False)
        view = self.view_class.as_view()

        response = view(request, token=token)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
开发者ID:mbrondani,项目名称:django-user-management,代码行数:12,代码来源:test_views.py

示例15: test_get

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

        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


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