Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions netbox_lifecycle/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SupportSKUIndex(SearchIndex):
('description', 4000),
('comments', 5000),
)
display_attrs = ('vendor', 'description')
display_attrs = ('manufacturer', 'description')


@register_search
Expand All @@ -33,7 +33,7 @@ class SupportContractIndex(SearchIndex):
('description', 4000),
('comments', 5000),
)
display_attrs = ('contract', 'sku', 'device', 'license', 'description')
display_attrs = ('vendor', 'start', 'renewal', 'end', 'description')


@register_search
Expand Down
36 changes: 36 additions & 0 deletions netbox_lifecycle/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ class SearchIndexDisplayAttrsTestCase(TestCase):
Search error "SupportContractAssignment has no field named 'vendor'"
"""

def test_support_sku_display_attrs_are_valid_fields(self):
"""
SupportSKUIndex.display_attrs should only reference
fields that exist on the SupportSKU model.
"""
index = SupportSKUIndex()
model = index.model

for attr in index.display_attrs:
# This should not raise FieldDoesNotExist
try:
model._meta.get_field(attr)
except FieldDoesNotExist:
self.fail(
f"SupportSKUIndex.display_attrs references "
f"non-existent field '{attr}' on {model.__name__}"
)

def test_support_contract_display_attrs_are_valid_fields(self):
"""
SupportContractIndex.display_attrs should only reference
fields that exist on the SupportContract model.
"""
index = SupportContractIndex()
model = index.model

for attr in index.display_attrs:
# This should not raise FieldDoesNotExist
try:
model._meta.get_field(attr)
except FieldDoesNotExist:
self.fail(
f"SupportContractIndex.display_attrs references "
f"non-existent field '{attr}' on {model.__name__}"
)

def test_support_contract_assignment_display_attrs_are_valid_fields(self):
"""
SupportContractAssignmentIndex.display_attrs should only reference
Expand Down
Loading