kopia lustrzana https://github.com/wagtail/wagtail
Change test util to handle custom user models
This should handle custom user models that use either username or email as the 'USERNAME_FIELD'pull/2256/merge
rodzic
eb269cab9c
commit
416e4be27b
|
@ -14,11 +14,19 @@ from django.utils.text import slugify
|
|||
|
||||
class WagtailTestUtils(object):
|
||||
def login(self):
|
||||
user_model = get_user_model()
|
||||
# Create a user
|
||||
user = get_user_model().objects.create_superuser(username='test', email='test@email.com', password='password')
|
||||
user_data = {}
|
||||
user_data[user_model.USERNAME_FIELD] = 'test@email.com'
|
||||
user_data['password'] = 'password'
|
||||
|
||||
for field in user_model.REQUIRED_FIELDS:
|
||||
user_data[field] = field
|
||||
|
||||
user = user_model.objects.create_superuser(**user_data)
|
||||
|
||||
# Login
|
||||
self.client.login(username='test', password='password')
|
||||
self.client.login(password='password', **{user_model.USERNAME_FIELD: 'test@email.com'})
|
||||
|
||||
return user
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue