Enable filter on blacklists & tlds

Can filter on blacklists by pattern and tlds by name.
Deleted from doc that filters are supported on records.
Added unit tests

Change-Id: I541ebc46424b51603a1b95afc36f1c9eb5f1e2a4
Closes-Bug: 1466649
This commit is contained in:
mimi8890 2015-07-07 20:35:28 +00:00 committed by Kiall Mac Innes
parent 8aa2dd709d
commit 368ae4363e
5 changed files with 69 additions and 4 deletions

View File

@ -53,7 +53,7 @@ class BlacklistsController(rest.RestController):
params, self.SORT_KEYS)
# Extract any filter params
accepted_filters = ('pattern')
accepted_filters = ('pattern', )
criterion = self._apply_filter_params(
params, accepted_filters, {})

View File

@ -51,7 +51,7 @@ class TldsController(rest.RestController):
params, self.SORT_KEYS)
# Extract any filter params.
accepted_filters = ('name')
accepted_filters = ('name', )
criterion = self._apply_filter_params(
params, accepted_filters, {})

View File

@ -14,6 +14,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import six
from designate.tests.test_api.test_v2 import ApiV2TestCase
@ -127,3 +129,35 @@ class ApiV2BlacklistsTest(ApiV2TestCase):
def test_update_bkaclist_invalid_id(self):
self._assert_invalid_uuid(self.client.patch_json, '/blacklists/%s')
def test_get_blacklists_filter(self):
# Add blacklists for testing
self.policy({'create_blacklists': '@'})
fixtures = [
self.get_blacklist_fixture(fixture=0),
self.get_blacklist_fixture(fixture=1)
]
for fixture in fixtures:
response = self.client.post_json('/blacklists/', fixture)
get_urls = [
# Filter by Pattern
'/blacklists?pattern=blacklisted.com.',
'/blacklists?pattern=blacklisted*'
]
correct_results = [1, 2]
for get_url, correct_result in \
six.moves.zip(get_urls, correct_results):
self.policy({'find_blacklists': '@'})
response = self.client.get(get_url)
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
# Check that the correct number of recordsets match
self.assertEqual(correct_result, len(response.json['blacklists']))

View File

@ -12,6 +12,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import six
from designate.tests.test_api.test_v2 import ApiV2TestCase
@ -125,3 +127,33 @@ class ApiV2TldsTest(ApiV2TestCase):
def test_update_tld_invalid_id(self):
self._assert_invalid_uuid(self.client.patch_json, '/tlds/%s')
def test_get_tld_filter(self):
self.policy({'create_tld': '@'})
fixtures = [
self.get_tld_fixture(0),
self.get_tld_fixture(1)
]
for fixture in fixtures:
response = self.client.post_json('/tlds/', fixture)
get_urls = [
'/tlds?name=com',
'/tlds?name=co*'
]
correct_results = [1, 2]
for get_url, correct_result in \
six.moves.zip(get_urls, correct_results):
self.policy({'find_tlds': '@'})
response = self.client.get(get_url)
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
# Check that the correct number of tlds match
self.assertEqual(correct_result, len(response.json['tlds']))

View File

@ -275,8 +275,7 @@ Filtering
Currently, the following attributes support filtering:
* **Blacklists**: pattern
* **Records**: data
* **Recordsets**: name, type, ttl
* **Recordsets**: name, type, ttl, data, description, status
* **TLDs**: name
* **Zones**: name, email