Add description filter support to TLD list API
The TLD list API endpoint previously only supported filtering by name, despite TLDs having a description field that is displayed in the client. This change adds 'description' to the accepted_filters in the TLDs controller, enabling users to filter TLDs by description using exact matches or wildcards. This brings TLD filtering in line with other resources such as zones and recordsets, which already support description filtering. Closes-Bug: #2116331 Generated-By: Claude Code Sonnet 4.5 Change-Id: Ia75345dc38d060bdd9f69d183e613373af1dca4f Signed-off-by: Omer <oschwart@redhat.com>
This commit is contained in:
1 parent
689a5490ba
commit
9ac42de5a5
5 files changed
+39
-2
No files matched your search
@@ -155,6 +155,7 @@ Request
|
||||
- marker: marker
|
||||
- sort_dir: sort_dir
|
||||
- sort_key: sort_key
|
||||
- description: tld_description_filter
|
||||
- name: tld_name_filter
|
||||
|
||||
|
||||
|
||||
@@ -280,6 +280,14 @@ target_project_id_filter:
|
||||
type: string
|
||||
min_version: 2.1
|
||||
|
||||
tld_description_filter:
|
||||
description: |
|
||||
Filter results to only show tlds that have a description matching the
|
||||
filter. Use ``*`` as a wildcard.
|
||||
in: query
|
||||
required: false
|
||||
type: string
|
||||
|
||||
tld_name_filter:
|
||||
description: |
|
||||
Filter results to only show tlds that have a name matching the filter
|
||||
|
||||
@@ -51,7 +51,7 @@ class TldsController(rest.RestController):
|
||||
context, params, self.SORT_KEYS)
|
||||
|
||||
# Extract any filter params.
|
||||
accepted_filters = ('name', )
|
||||
accepted_filters = ('name', 'description')
|
||||
criterion = self._apply_filter_params(
|
||||
params, accepted_filters, {})
|
||||
|
||||
|
||||
@@ -198,7 +198,28 @@ class ApiV2TldsTest(v2.ApiV2TestCase):
|
||||
# Check that the correct number of tlds match
|
||||
self.assertEqual(correct_result, len(response.json['tlds']))
|
||||
|
||||
def test_get_tld_filter_by_description(self):
|
||||
self.policy({'create_tld': '@'})
|
||||
|
||||
# Create TLDs with descriptions
|
||||
self.create_tld(name='com', description='Commercial TLD')
|
||||
self.create_tld(name='org', description='Organization TLD')
|
||||
self.create_tld(name='net', description='Network TLD')
|
||||
|
||||
self.policy({'find_tlds': '@'})
|
||||
|
||||
# Test exact match
|
||||
response = self.client.get('/tlds?description=Commercial TLD')
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(1, len(response.json['tlds']))
|
||||
|
||||
# Test wildcard match
|
||||
response = self.client.get('/tlds?description=*TLD')
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual(3, len(response.json['tlds']))
|
||||
|
||||
def test_invalid_tld_filter(self):
|
||||
invalid_url = '/tlds?description=test'
|
||||
invalid_url = '/tlds?invalid_filter=test'
|
||||
self._assert_exception(
|
||||
'bad_request', 400, self.client.get, invalid_url)
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added support for filtering TLDs by description in the API.
|
||||
The TLD list endpoint now accepts a ``description`` query parameter
|
||||
to filter results, matching the pattern used by other resources like
|
||||
zones and recordsets. Wildcard filtering is supported using ``*``.
|
||||
Reference in new issue
Block a user