Skip to content

Commit

Permalink
fix test_tags_filter() test (#786)
Browse files Browse the repository at this point in the history
* fix test_tags_filter() test

* changelog

* rename changelog from .fixed and .housekeeping
  • Loading branch information
HanlinMiao authored Aug 7, 2024
1 parent b241354 commit 4991993
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions changes/786.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed incorrect test data setup for `test_tags_filter()` test for `ConfigPlanFilterTestCase`.
28 changes: 11 additions & 17 deletions nautobot_golden_config/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,17 @@ class Meta:
class ConfigPlanFilterSet(NautobotFilterSet):
"""Inherits Base Class NautobotFilterSet."""

q = django_filters.CharFilter(
method="search",
label="Search",
q = SearchFilter(
filter_predicates={
"device__name": {
"lookup_expr": "icontains",
"preprocessor": str,
},
"change_control_id": {
"lookup_expr": "icontains",
"preprocessor": str,
},
},
)
device_id = django_filters.ModelMultipleChoiceFilter(
queryset=Device.objects.all(),
Expand Down Expand Up @@ -421,20 +429,6 @@ class ConfigPlanFilterSet(NautobotFilterSet):
to_field_name="name",
label="Status",
)
# tags = TagFilter()

q = SearchFilter(
filter_predicates={
"device__name": {
"lookup_expr": "icontains",
"preprocessor": str,
},
"change_control_id": {
"lookup_expr": "icontains",
"preprocessor": str,
},
},
)

class Meta:
"""Boilerplate filter Meta data for Config Plan."""
Expand Down
3 changes: 3 additions & 0 deletions nautobot_golden_config/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Unit tests for nautobot_golden_config models."""

from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from nautobot.dcim.models import Device, Platform
from nautobot.extras.models import Status, Tag
Expand Down Expand Up @@ -404,6 +405,8 @@ def setUp(self):
self.status2 = Status.objects.get(name="Approved")
self.tag1, _ = Tag.objects.get_or_create(name="Tag 1")
self.tag2, _ = Tag.objects.get_or_create(name="Tag 2")
self.tag1.content_types.set([ContentType.objects.get_for_model(models.ConfigPlan)])
self.tag2.content_types.set([ContentType.objects.get_for_model(models.ConfigPlan)])
self.job_result1 = create_job_result()
self.job_result2 = create_job_result()
self.config_plan1 = models.ConfigPlan.objects.create(
Expand Down

0 comments on commit 4991993

Please sign in to comment.