diff options
| author | Josh Schneier <josh.schneier@gmail.com> | 2018-08-02 13:29:48 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-08-04 08:44:25 -0400 |
| commit | 793e9bb35af34aa11320866bcc6ad8edaf1480a7 (patch) | |
| tree | 7491d0df04353c14a5cb1148bef8ea8a802e38b1 /tests/auth_tests/models | |
| parent | f1fbef6cd171ddfae41fcc901f1f60ccad039f51 (diff) | |
Fixed #29628 -- Made createsuperuser validate password against username and required fields.
Diffstat (limited to 'tests/auth_tests/models')
| -rw-r--r-- | tests/auth_tests/models/custom_user.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/auth_tests/models/custom_user.py b/tests/auth_tests/models/custom_user.py index ad8b4c1212..a46f1d5a9c 100644 --- a/tests/auth_tests/models/custom_user.py +++ b/tests/auth_tests/models/custom_user.py @@ -9,7 +9,7 @@ from django.db import models # that every user provide a date of birth. This lets us test # changes in username datatype, and non-text required fields. class CustomUserManager(BaseUserManager): - def create_user(self, email, date_of_birth, password=None): + def create_user(self, email, date_of_birth, password=None, **fields): """ Creates and saves a User with the given email and password. """ @@ -19,14 +19,15 @@ class CustomUserManager(BaseUserManager): user = self.model( email=self.normalize_email(email), date_of_birth=date_of_birth, + **fields ) user.set_password(password) user.save(using=self._db) return user - def create_superuser(self, email, password, date_of_birth): - u = self.create_user(email, password=password, date_of_birth=date_of_birth) + def create_superuser(self, email, password, date_of_birth, **fields): + u = self.create_user(email, password=password, date_of_birth=date_of_birth, **fields) u.is_admin = True u.save(using=self._db) return u @@ -37,11 +38,12 @@ class CustomUser(AbstractBaseUser): is_active = models.BooleanField(default=True) is_admin = models.BooleanField(default=False) date_of_birth = models.DateField() + first_name = models.CharField(max_length=50) custom_objects = CustomUserManager() USERNAME_FIELD = 'email' - REQUIRED_FIELDS = ['date_of_birth'] + REQUIRED_FIELDS = ['date_of_birth', 'first_name'] def __str__(self): return self.email |
