10
10
from django .urls import path
11
11
from django .urls import reverse
12
12
13
- from django_github_app .admin import EventLogModelAdmin
14
- from django_github_app .admin import InstallationModelAdmin
15
- from django_github_app .admin import RepositoryModelAdmin
16
- from django_github_app .models import EventLog
17
- from django_github_app .models import Installation
18
- from django_github_app .models import Repository
19
-
20
13
21
14
class TestAdminSite (AdminSite ):
22
15
def __init__ (self ):
23
16
super ().__init__ (name = "testadmin" )
24
17
25
18
26
19
admin_site = TestAdminSite ()
27
- admin_site .register (EventLog , EventLogModelAdmin )
28
- admin_site .register (Installation , InstallationModelAdmin )
29
- admin_site .register (Repository , RepositoryModelAdmin )
20
+
21
+
22
+ @pytest .fixture (scope = "session" )
23
+ def test_admin_site ():
24
+ return admin_site
30
25
31
26
32
27
@pytest .fixture (autouse = True )
33
- def setup ():
28
+ def setup_admin_urls ():
29
+ """Set up admin URLs for testing."""
34
30
urlpatterns = [
35
31
path ("admin/" , admin_site .urls ),
36
32
]
@@ -51,6 +47,7 @@ def setup():
51
47
52
48
@pytest .fixture
53
49
def admin_client (django_user_model , client ):
50
+ """Create and return an admin client."""
54
51
admin_user = django_user_model .objects .create_superuser (
55
52
username = "admin" , email = "admin@example.com" , password = "test"
56
53
)
@@ -64,14 +61,17 @@ def admin_client(django_user_model, client):
64
61
pytest .param (
65
62
model ,
66
63
model_admin ,
67
- id = f"{ str ( model_admin ). replace ( '.' , '_' ) } " ,
64
+ id = f"{ model . _meta . app_label } _ { model . _meta . model_name } " ,
68
65
)
69
66
for model , model_admin in admin_site ._registry .items ()
70
67
],
71
68
)
72
69
@pytest .mark .django_db
73
70
class TestModelAdmins :
71
+ """Test suite for Django model admins."""
72
+
74
73
def test_changelist (self , admin_client , model , model_admin ):
74
+ """Test the changelist view for each model admin."""
75
75
url = reverse (
76
76
f"{ admin_site .name } :{ model ._meta .app_label } _{ model ._meta .model_name } _changelist"
77
77
)
@@ -81,6 +81,7 @@ def test_changelist(self, admin_client, model, model_admin):
81
81
assert response .status_code == HTTPStatus .OK
82
82
83
83
def test_add (self , admin_client , model , model_admin ):
84
+ """Test the add view for each model admin."""
84
85
url = reverse (
85
86
f"{ admin_site .name } :{ model ._meta .app_label } _{ model ._meta .model_name } _add"
86
87
)
0 commit comments