From e73a95d4bb28bab065e2bf0417e2c0c71d76542e Mon Sep 17 00:00:00 2001 From: mimi8890 Date: Tue, 7 Jul 2015 20:35:28 +0000 Subject: [PATCH] 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 --- designate/api/v2/controllers/blacklists.py | 2 +- designate/api/v2/controllers/tlds.py | 2 +- .../tests/test_api/test_v2/test_blacklists.py | 34 +++++++++++++++++++ designate/tests/test_api/test_v2/test_tlds.py | 32 +++++++++++++++++ doc/source/rest/v2/collections.rst | 1 - 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/designate/api/v2/controllers/blacklists.py b/designate/api/v2/controllers/blacklists.py index 8d78aafcf..ae95c9577 100644 --- a/designate/api/v2/controllers/blacklists.py +++ b/designate/api/v2/controllers/blacklists.py @@ -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, {}) diff --git a/designate/api/v2/controllers/tlds.py b/designate/api/v2/controllers/tlds.py index f047e5bba..8f339ef66 100644 --- a/designate/api/v2/controllers/tlds.py +++ b/designate/api/v2/controllers/tlds.py @@ -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, {}) diff --git a/designate/tests/test_api/test_v2/test_blacklists.py b/designate/tests/test_api/test_v2/test_blacklists.py index 34746bfba..98ff479c1 100644 --- a/designate/tests/test_api/test_v2/test_blacklists.py +++ b/designate/tests/test_api/test_v2/test_blacklists.py @@ -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'])) diff --git a/designate/tests/test_api/test_v2/test_tlds.py b/designate/tests/test_api/test_v2/test_tlds.py index b28d03aa3..9b4f075ab 100644 --- a/designate/tests/test_api/test_v2/test_tlds.py +++ b/designate/tests/test_api/test_v2/test_tlds.py @@ -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'])) diff --git a/doc/source/rest/v2/collections.rst b/doc/source/rest/v2/collections.rst index 4dd3aebb8..220282912 100644 --- a/doc/source/rest/v2/collections.rst +++ b/doc/source/rest/v2/collections.rst @@ -275,7 +275,6 @@ Filtering Currently, the following attributes support filtering: * **Blacklists**: pattern - * **Records**: data * **Recordsets**: name, type, ttl, data, description, status * **TLDs**: name * **Zones**: name, email, ttl, description, status