mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-17 03:51:02 +03:00
Merge pull request #3018 from Andrew-Chen-Wang/patch-6
This commit is contained in:
commit
d62ad403a4
|
@ -1,6 +1,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth import admin as auth_admin
|
from django.contrib.auth import admin as auth_admin
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm, UserCreationForm
|
from {{ cookiecutter.project_slug }}.users.forms import UserChangeForm, UserCreationForm
|
||||||
|
|
||||||
|
@ -12,8 +13,22 @@ class UserAdmin(auth_admin.UserAdmin):
|
||||||
|
|
||||||
form = UserChangeForm
|
form = UserChangeForm
|
||||||
add_form = UserCreationForm
|
add_form = UserCreationForm
|
||||||
fieldsets = (("User", {"fields": ("name",)}),) + tuple(
|
fieldsets = (
|
||||||
auth_admin.UserAdmin.fieldsets
|
(None, {"fields": ("username", "password")}),
|
||||||
|
(_("Personal info"), {"fields": ("name", "email")}),
|
||||||
|
(
|
||||||
|
_("Permissions"),
|
||||||
|
{
|
||||||
|
"fields": (
|
||||||
|
"is_active",
|
||||||
|
"is_staff",
|
||||||
|
"is_superuser",
|
||||||
|
"groups",
|
||||||
|
"user_permissions",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
|
||||||
)
|
)
|
||||||
list_display = ["username", "name", "is_superuser"]
|
list_display = ["username", "name", "is_superuser"]
|
||||||
search_fields = ["name"]
|
search_fields = ["name"]
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
import pytest
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from {{ cookiecutter.project_slug }}.users.models import User
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
class TestUserAdmin:
|
||||||
|
def test_changelist(self, admin_client):
|
||||||
|
url = reverse("admin:users_user_changelist")
|
||||||
|
response = admin_client.get(url)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
def test_search(self, admin_client):
|
||||||
|
url = reverse("admin:users_user_changelist")
|
||||||
|
response = admin_client.get(url, data={"q": "test"})
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
def test_add(self, admin_client):
|
||||||
|
url = reverse("admin:users_user_add")
|
||||||
|
response = admin_client.get(url)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
response = admin_client.post(
|
||||||
|
url,
|
||||||
|
data={
|
||||||
|
"username": "test",
|
||||||
|
"password1": "My_R@ndom-P@ssw0rd",
|
||||||
|
"password2": "My_R@ndom-P@ssw0rd",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert User.objects.filter(username="test").exists()
|
||||||
|
|
||||||
|
def test_view_user(self, admin_client):
|
||||||
|
user = User.objects.get(username="admin")
|
||||||
|
url = reverse("admin:users_user_change", kwargs={"object_id": user.pk})
|
||||||
|
response = admin_client.get(url)
|
||||||
|
assert response.status_code == 200
|
Loading…
Reference in New Issue
Block a user