Skip to content

Commit 43c9b5c

Browse files
authored
Fix filteriong on zone vs zone_id internally in the Host model. (#574)
1 parent aaef5ad commit 43c9b5c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

mreg/api/v1/filters.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def filter_queryset(self, queryset):
147147

148148

149149
class HostFilterSet(filters.FilterSet):
150+
zone = filters.NumberFilter(field_name="zone_id")
151+
zone__name = filters.CharFilter(field_name="zone_id__name")
152+
150153
class Meta:
151154
model = Host
152155
fields = {
@@ -186,8 +189,11 @@ class Meta:
186189
"srvs__weight": INT_OPERATORS,
187190
"srvs__port": INT_OPERATORS,
188191
"srvs__ttl": INT_OPERATORS,
189-
"zone": INT_OPERATORS,
190-
"zone__name": STRING_OPERATORS,
192+
# These are relationships to Zone, which for some reason are named zone_id in the host _model_,
193+
# even though the field in the ForwardZone model is named zone and the field returned to the
194+
# user is called zone...
195+
"zone_id": INT_OPERATORS,
196+
"zone_id__name": STRING_OPERATORS,
191197
**CREATED_UPDATED,
192198
}
193199

mreg/api/v1/tests/tests_zones.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ def test_zones_404_not_found(self):
233233
""""Deleting a non-existing entry should return 404"""
234234
self.assert_delete_and_404(self.basepath + '1.11.in-addr.arpa')
235235

236+
def test_zone_by_host_200_ok_but_empty(self):
237+
res = self.assert_get(f'/hosts/?zone={self.zone_one.pk}')
238+
self.assertEqual(res.json()['count'], 0)
239+
236240

237241
class ZonesForwardDelegationTestCase(MregAPITestCase):
238242
""" This class defines test testsuite for api/zones/forward/<name>/delegations/

0 commit comments

Comments
 (0)