Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix filteriong on zone vs zone_id internally in the Host model. #574

Merged
merged 1 commit into from
Feb 19, 2025
Merged
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
10 changes: 8 additions & 2 deletions mreg/api/v1/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def filter_queryset(self, queryset):


class HostFilterSet(filters.FilterSet):
zone = filters.NumberFilter(field_name="zone_id")
zone__name = filters.CharFilter(field_name="zone_id__name")

class Meta:
model = Host
fields = {
Expand Down Expand Up @@ -186,8 +189,11 @@ class Meta:
"srvs__weight": INT_OPERATORS,
"srvs__port": INT_OPERATORS,
"srvs__ttl": INT_OPERATORS,
"zone": INT_OPERATORS,
"zone__name": STRING_OPERATORS,
# These are relationships to Zone, which for some reason are named zone_id in the host _model_,
# even though the field in the ForwardZone model is named zone and the field returned to the
# user is called zone...
"zone_id": INT_OPERATORS,
"zone_id__name": STRING_OPERATORS,
**CREATED_UPDATED,
}

Expand Down
4 changes: 4 additions & 0 deletions mreg/api/v1/tests/tests_zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ def test_zones_404_not_found(self):
""""Deleting a non-existing entry should return 404"""
self.assert_delete_and_404(self.basepath + '1.11.in-addr.arpa')

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


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