mirror of https://github.com/django/django.git
Completed test coverage for createsuperuser command.
This commit is contained in:
parent
f08651c06c
commit
67c34c1a37
|
@ -282,13 +282,11 @@ class Command(BaseCommand):
|
|||
def username_is_unique(self):
|
||||
if self.username_field.unique:
|
||||
return True
|
||||
for unique_constraint in self.UserModel._meta.total_unique_constraints:
|
||||
if (
|
||||
len(unique_constraint.fields) == 1
|
||||
and unique_constraint.fields[0] == self.username_field.name
|
||||
):
|
||||
return True
|
||||
return False
|
||||
return any(
|
||||
len(unique_constraint.fields) == 1
|
||||
and unique_constraint.fields[0] == self.username_field.name
|
||||
for unique_constraint in self.UserModel._meta.total_unique_constraints
|
||||
)
|
||||
|
||||
def _validate_username(self, username, verbose_field_name, database):
|
||||
"""Validate username. If invalid, return a string error message."""
|
||||
|
|
|
@ -312,6 +312,19 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
|||
# created password should be unusable
|
||||
self.assertFalse(u.has_usable_password())
|
||||
|
||||
def test_validate_username(self):
|
||||
msg = (
|
||||
"Enter a valid username. This value may contain only letters, numbers, "
|
||||
"and @/./+/-/_ characters."
|
||||
)
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
call_command(
|
||||
"createsuperuser",
|
||||
interactive=False,
|
||||
username="🤠",
|
||||
email="joe@somewhere.org",
|
||||
)
|
||||
|
||||
def test_non_ascii_verbose_name(self):
|
||||
@mock_inputs(
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue