本文整理汇总了Python中django.contrib.auth.management.get_default_username方法的典型用法代码示例。如果您正苦于以下问题:Python management.get_default_username方法的具体用法?Python management.get_default_username怎么用?Python management.get_default_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.management
的用法示例。
在下文中一共展示了management.get_default_username方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_non_ascii_verbose_name
# 需要导入模块: from django.contrib.auth import management [as 别名]
# 或者: from django.contrib.auth.management import get_default_username [as 别名]
def test_non_ascii_verbose_name(self):
@mock_inputs({
'password': "nopasswd",
"Uživatel (leave blank to use '%s'): " % get_default_username(): 'foo', # username (cz)
'email': 'nolocale@somewhere.org',
})
def test(self):
username_field = User._meta.get_field('username')
old_verbose_name = username_field.verbose_name
username_field.verbose_name = _('u\u017eivatel')
new_io = StringIO()
try:
call_command(
"createsuperuser",
interactive=True,
stdout=new_io,
stdin=MockTTY(),
)
finally:
username_field.verbose_name = old_verbose_name
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, 'Superuser created successfully.')
test(self)
示例2: test_default_username
# 需要导入模块: from django.contrib.auth import management [as 别名]
# 或者: from django.contrib.auth.management import get_default_username [as 别名]
def test_default_username(self):
"""createsuperuser uses a default username when one isn't provided."""
# Get the default username before creating a user.
default_username = get_default_username()
new_io = StringIO()
entered_passwords = ['password', 'password']
def return_passwords():
return entered_passwords.pop(0)
@mock_inputs({'password': return_passwords, 'username': '', 'email': ''})
def test(self):
call_command(
'createsuperuser',
interactive=True,
stdin=MockTTY(),
stdout=new_io,
stderr=new_io,
)
self.assertEqual(new_io.getvalue().strip(), 'Superuser created successfully.')
self.assertTrue(User.objects.filter(username=default_username).exists())
test(self)
示例3: test_simple
# 需要导入模块: from django.contrib.auth import management [as 别名]
# 或者: from django.contrib.auth.management import get_default_username [as 别名]
def test_simple(self):
management.get_system_username = lambda: 'joe'
self.assertEqual(management.get_default_username(), 'joe')
示例4: test_existing
# 需要导入模块: from django.contrib.auth import management [as 别名]
# 或者: from django.contrib.auth.management import get_default_username [as 别名]
def test_existing(self):
User.objects.create(username='joe')
management.get_system_username = lambda: 'joe'
self.assertEqual(management.get_default_username(), '')
self.assertEqual(
management.get_default_username(check_db=False), 'joe')
示例5: test_i18n
# 需要导入模块: from django.contrib.auth import management [as 别名]
# 或者: from django.contrib.auth.management import get_default_username [as 别名]
def test_i18n(self):
# 'Julia' with accented 'u':
management.get_system_username = lambda: 'J\xfalia'
self.assertEqual(management.get_default_username(), 'julia')