1010from django .urls import path
1111from django .urls import reverse
1212
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-
2013
2114class TestAdminSite (AdminSite ):
2215 def __init__ (self ):
2316 super ().__init__ (name = "testadmin" )
2417
2518
2619admin_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
3025
3126
3227@pytest .fixture (autouse = True )
33- def setup ():
28+ def setup_admin_urls ():
29+ """Set up admin URLs for testing."""
3430 urlpatterns = [
3531 path ("admin/" , admin_site .urls ),
3632 ]
@@ -51,6 +47,7 @@ def setup():
5147
5248@pytest .fixture
5349def admin_client (django_user_model , client ):
50+ """Create and return an admin client."""
5451 admin_user = django_user_model .objects .create_superuser (
5552 username = "admin" ,
email = "[email protected] " ,
password = "test" 5653 )
@@ -64,14 +61,17 @@ def admin_client(django_user_model, client):
6461 pytest .param (
6562 model ,
6663 model_admin ,
67- id = f"{ str ( model_admin ). replace ( '.' , '_' ) } " ,
64+ id = f"{ model . _meta . app_label } _ { model . _meta . model_name } " ,
6865 )
6966 for model , model_admin in admin_site ._registry .items ()
7067 ],
7168)
7269@pytest .mark .django_db
7370class TestModelAdmins :
71+ """Test suite for Django model admins."""
72+
7473 def test_changelist (self , admin_client , model , model_admin ):
74+ """Test the changelist view for each model admin."""
7575 url = reverse (
7676 f"{ admin_site .name } :{ model ._meta .app_label } _{ model ._meta .model_name } _changelist"
7777 )
@@ -81,6 +81,7 @@ def test_changelist(self, admin_client, model, model_admin):
8181 assert response .status_code == HTTPStatus .OK
8282
8383 def test_add (self , admin_client , model , model_admin ):
84+ """Test the add view for each model admin."""
8485 url = reverse (
8586 f"{ admin_site .name } :{ model ._meta .app_label } _{ model ._meta .model_name } _add"
8687 )
0 commit comments