Skip to content

Commit 503ef3e

Browse files
jnnsbluetech
authored andcommitted
Fix admin_client & admin_user for custom user model
Relying on `User.USERNAME_FIELD` is enough for light customization and doesn't require `extra_arguments`. Esoteric user models probably need a specially tailored manager anyway and most likely a custom `django_user` fixture that goes with that.
1 parent a079cd6 commit 503ef3e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pytest_django/fixtures.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,12 @@ def admin_user(db, django_user_model, django_username_field):
293293
# so we can assume so as well.
294294
user = UserModel._default_manager.get_by_natural_key(username)
295295
except UserModel.DoesNotExist:
296-
extra_fields = {}
297-
if username_field not in ("username", "email"):
298-
extra_fields[username_field] = "admin"
299296
user = UserModel._default_manager.create_superuser(
300-
username, "[email protected]", "password", **extra_fields
297+
**{
298+
"email": "[email protected]",
299+
"password": "password",
300+
username_field: username,
301+
}
301302
)
302303
return user
303304

0 commit comments

Comments
 (0)