Skip to content

Commit 7347270

Browse files
committed
Add iexact api filter to charfields
1 parent 8af329b commit 7347270

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/ralph/api/filters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,15 @@ class LookupFilterBackend(BaseFilterBackend):
170170
"isnull",
171171
},
172172
models.CharField: {
173+
"iexact",
173174
"ne",
174175
"startswith",
175176
"istartswith",
176177
"endswith",
177-
"icontains",
178+
"iendswith",
178179
"contains",
180+
"icontains",
179181
"in",
180-
"iendswith",
181182
"isnull",
182183
"regex",
183184
"iregex",

src/ralph/assets/tests/test_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,14 @@ def test_filter_by_hostname(self):
915915
self.assertEqual(response.status_code, status.HTTP_200_OK)
916916
self.assertEqual(response.data["count"], 1)
917917

918+
def test_filter_by_hostname_case_insensitive(self):
919+
url = "{}?{}".format(
920+
reverse("dchost-list"), urlencode({"hostname__iexact": "AAAA"})
921+
)
922+
response = self.client.get(url, format="json")
923+
self.assertEqual(response.status_code, status.HTTP_200_OK)
924+
self.assertEqual(response.data["count"], 1)
925+
918926
def test_filter_by_name(self):
919927
url = "{}?{}".format(reverse("dchost-list"), urlencode({"name": "aaaa"}))
920928
response = self.client.get(url, format="json")

0 commit comments

Comments
 (0)