Skip to content

Commit

Permalink
fix device._name ordering (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov authored Feb 5, 2025
1 parent f56eb98 commit 8918109
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions validity/netbox_changes/current.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# NetBox 4.2
from .old import *


DEVICE_NAME_ORDER = "name"
1 change: 1 addition & 0 deletions validity/netbox_changes/oldest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@


QUEUE_CREATE_ACTION = "create"
DEVICE_NAME_ORDER = "_name"
7 changes: 6 additions & 1 deletion validity/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"),
Expand Down
5 changes: 3 additions & 2 deletions validity/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 8918109

Please sign in to comment.