feat: connect django admin smoke tests
This commit is contained in:
+20
-1
@@ -1,3 +1,22 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
|
||||
|
||||
# Register your models here.
|
||||
from .models import User
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(DjangoUserAdmin):
|
||||
fieldsets = DjangoUserAdmin.fieldsets + (
|
||||
("Cmhub", {"fields": ("payment_user_id", "status", "created_at")}),
|
||||
)
|
||||
readonly_fields = ("created_at",)
|
||||
list_display = (
|
||||
"username",
|
||||
"email",
|
||||
"status",
|
||||
"is_staff",
|
||||
"is_active",
|
||||
"created_at",
|
||||
)
|
||||
list_filter = DjangoUserAdmin.list_filter + ("status",)
|
||||
search_fields = ("username", "email", "payment_user_id")
|
||||
|
||||
+21
-1
@@ -1,3 +1,23 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
class AdminSmokeTests(TestCase):
|
||||
def test_custom_user_is_registered_in_admin(self):
|
||||
self.assertIn(get_user_model(), admin.site._registry)
|
||||
|
||||
def test_superuser_can_login_to_admin(self):
|
||||
user_model = get_user_model()
|
||||
user_model.objects.create_superuser(
|
||||
username="admin",
|
||||
email="admin@example.com",
|
||||
password="test-password",
|
||||
)
|
||||
|
||||
logged_in = self.client.login(username="admin", password="test-password")
|
||||
self.assertTrue(logged_in)
|
||||
|
||||
response = self.client.get(reverse("admin:index"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
Reference in New Issue
Block a user