本文整理汇总了Python中user_management.models.tests.factories.UserFactory类的典型用法代码示例。如果您正苦于以下问题:Python UserFactory类的具体用法?Python UserFactory怎么用?Python UserFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_put_invalid_token
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,代码行数:10,代码来源:test_views.py
示例2: test_post
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,代码行数:13,代码来源:test_views.py
示例3: test_deserialize_update_email_in_use
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,代码行数:14,代码来源:test_serializers.py
示例4: test_post_rate_limit
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,代码行数:15,代码来源:test_throttling.py
示例5: test_post
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,代码行数:15,代码来源:test_views.py
示例6: test_post_user_not_confirmed
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,代码行数:15,代码来源:test_views.py
示例7: test_delete_without_avatar
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,代码行数:7,代码来源:test_views.py
示例8: test_duplicate_email
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,代码行数:16,代码来源:test_views.py
示例9: test_existent_email
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,代码行数:27,代码来源:test_views.py
示例10: test_deserialize
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,代码行数:7,代码来源:test_serializers.py
示例11: test_post_different_user_logged_in
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,代码行数:16,代码来源:test_views.py
示例12: test_get
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,代码行数:8,代码来源:test_views.py
示例13: test_get_no_avatar
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,代码行数:8,代码来源:test_views.py
示例14: test_post_email_already_verified
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,代码行数:8,代码来源:test_views.py
示例15: test_patch
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,代码行数:17,代码来源:test_views.py
示例16: test_post_verified_email
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,代码行数:9,代码来源:test_views.py
示例17: test_send_email_other_user
def test_send_email_other_user(self):
"""Assert a user can not request a confirmation email for another user."""
user, other_user = UserFactory.create_batch(2)
data = {'email': other_user.email}
request = self.create_request('post', user=user, data=data)
view = self.view_class.as_view()
response = view(request)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
开发者ID:EEtoJava,项目名称:django-user-management,代码行数:9,代码来源:test_views.py
示例18: test_options
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,代码行数:9,代码来源:test_views.py
示例19: test_post_invalid_user
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,代码行数:9,代码来源:test_views.py
示例20: test_serialize
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,代码行数:10,代码来源:test_serializers.py
注:本文中的user_management.models.tests.factories.UserFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论