diff --git a/validity/netbox_changes/current.py b/validity/netbox_changes/current.py index 2d21ae8..b921f26 100644 --- a/validity/netbox_changes/current.py +++ b/validity/netbox_changes/current.py @@ -1,2 +1,5 @@ # NetBox 4.2 from .old import * + + +DEVICE_NAME_ORDER = "name" diff --git a/validity/netbox_changes/oldest.py b/validity/netbox_changes/oldest.py index a7cf124..3a1bd7d 100644 --- a/validity/netbox_changes/oldest.py +++ b/validity/netbox_changes/oldest.py @@ -6,3 +6,4 @@ QUEUE_CREATE_ACTION = "create" +DEVICE_NAME_ORDER = "_name" diff --git a/validity/tables.py b/validity/tables.py index 9a6832d..d6540f2 100644 --- a/validity/tables.py +++ b/validity/tables.py @@ -16,6 +16,7 @@ from utilities.templatetags.builtins.filters import isodatetime from validity import models +from validity.netbox_changes import DEVICE_NAME_ORDER from validity.templatetags.validity import colorful_percentage @@ -233,7 +234,11 @@ def render(self, value): class ComplianceReportDeviceTable(BaseTable): device = TemplateColumn( - order_by=("_name",), template_code=DEVICE_LINK, linkify=True, accessor="name", attrs={"th": {"class": "col-2"}} + order_by=(DEVICE_NAME_ORDER), + template_code=DEVICE_LINK, + linkify=True, + accessor="name", + attrs={"th": {"class": "col-2"}}, ) compliance_passed = BooleanColumn( verbose_name=_("Compliance Passed"), diff --git a/validity/tests/test_views.py b/validity/tests/test_views.py index dea62da..5707134 100644 --- a/validity/tests/test_views.py +++ b/validity/tests/test_views.py @@ -166,10 +166,11 @@ def test_get_serialized_state(admin_client, item, monkeypatch): assert resp.status_code == HTTPStatus.OK +@pytest.mark.parametrize("query_params", [{}, {"sort": "device"}, {"sort": "-device"}]) @pytest.mark.django_db -def test_report_devices(admin_client): +def test_report_devices(admin_client, query_params): report = ReportFactory(passed_results=4, failed_results=2) - resp = admin_client.get(f"/plugins/validity/reports/{report.pk}/devices/") + resp = admin_client.get(f"/plugins/validity/reports/{report.pk}/devices/", query_params) assert resp.status_code == HTTPStatus.OK