本文整理汇总了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())
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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'))
示例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)
示例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))
示例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)
示例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)
示例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())
示例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)
示例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())