-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
from django.contrib import admin # noqa | ||
"""Django Admin customization for the core app.""" | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin | ||
from django.utils.translation import gettext_lazy as _ | ||
from core import models | ||
|
||
# Register your models here. | ||
class UserAdmin(BaseUserAdmin): | ||
"""Customize the user admin page.""" | ||
ordering = ['id'] | ||
list_display = ['email', 'name'] | ||
|
||
fieldsets = ( | ||
(None, {'fields': ('email', 'password')}), | ||
('Personal Info', {'fields': ('name',)}), | ||
( | ||
_('Permissions'), | ||
{ | ||
'fields': ('is_active', 'is_staff', 'is_superuser'), | ||
} | ||
), | ||
('Important dates', {'fields': ('last_login',)}), | ||
) | ||
add_fieldsets = ( | ||
(None, { | ||
|
||
'classes': ('wide',), | ||
'fields': ('email', 'password1', 'password2'), | ||
}), | ||
) | ||
|
||
admin.site.register(models.User, UserAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase, Client | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
|
||
class AdminSiteTests(TestCase): | ||
"""Test the admin site""" | ||
|
||
def setUp(self): | ||
"""Create user & client for testing""" | ||
self.client = Client() | ||
self.admin_user = get_user_model().objects.create_superuser( | ||
email='admin@example.com', | ||
password='password123', | ||
) | ||
self.client.force_login(self.admin_user) | ||
self.user = get_user_model().objects.create_user( | ||
email='user@example.com', | ||
password='password123', | ||
name='Test user full name', | ||
) | ||
|
||
def test_users_list(self): | ||
"""Test users are listed on user page""" | ||
url = reverse('admin:core_user_changelist') | ||
res = self.client.get(url) | ||
|
||
self.assertContains(res, self.user.name) | ||
self.assertContains(res, self.user.email) | ||
|
||
def test_user_change_page(self): | ||
"""Test user edit page works""" | ||
url = reverse('admin:core_user_change', args=[self.user.id]) | ||
res = self.client.get(url) | ||
|
||
self.assertEqual(res.status_code, 200) | ||
|
||
def test_create_user_page(self): | ||
"""Test create user page works""" | ||
url = reverse('admin:core_user_add') | ||
res = self.client.get(url) | ||
|
||
self.assertEqual(res.status_code, 200) |