本文整理汇总了Python中accounts.models.User.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python User.full_clean方法的具体用法?Python User.full_clean怎么用?Python User.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.full_clean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_creating_new_user
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import full_clean [as 别名]
def test_creating_new_user(self):
user = User()
user.username = "test"
user.email = "[email protected]"
user.set_password("test")
user.full_clean()
user.save()
all_users = User.objects.all()
self.assertEqual(len(all_users), 1)
user_from_database = all_users[0]
self.assertEquals(user_from_database, user)
示例2: test_duplicate_email_check
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import full_clean [as 别名]
def test_duplicate_email_check(self):
user = User()
user.username = "test"
user.email = "[email protected]"
user.set_password("test")
user.full_clean()
user.save()
with self.assertRaises(ValidationError):
user2 = User()
user2.username = "test2"
user2.email = "[email protected]"
user2.set_password("test")
user2.full_clean()
user2.save()
示例3: create_user_by_model
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import full_clean [as 别名]
def create_user_by_model(self, **user_data):
"""
Create User instance directly, by User model.
"""
user = User(**user_data)
try:
user.full_clean()
except ValidationError as exc:
raise AssertionError(
_(u'User saving error: %s' % str(exc)))
else:
if 'password' in user_data:
user.set_password(user_data['password'])
user.save()
return user