-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛(dashboard) adjust manager order in Consent model
Reordered `objects` and `active_objects` in the Consent model to ensure compatibility with Django admin expectations. Introduce a test to ensure the default Django manager is used in the admin setup, avoiding issues with custom managers.
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
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
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,31 @@ | ||
"""Dashboard consent admin tests.""" | ||
|
||
import pytest | ||
from django.contrib.admin.sites import AdminSite | ||
from django.urls import reverse | ||
|
||
from apps.consent.admin import ConsentAdmin | ||
from apps.consent.models import Consent | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_admin_manager_name(rf): | ||
"""Tests the name of the manager used by the Django admin to retrieve objects. | ||
For the Django admin, the manager used must be the default django manager | ||
(`objects`) and not a custom manager, which could lead to an unwanted loss of | ||
display of data. | ||
""" | ||
# Initialize admin | ||
site = AdminSite() | ||
admin = ConsentAdmin(Consent, site) | ||
|
||
# Request admin consent | ||
request = rf.get(reverse("admin:qcd_consent_consent_changelist")) | ||
|
||
# Get the queryset used by admin | ||
queryset = admin.get_queryset(request) | ||
|
||
# The manager name must be the default Django manager: `objects`. | ||
manager_name = queryset.model._default_manager.name | ||
assert manager_name == "objects" |