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:
parent
73b014b15f
commit
e73a95d4bb
@ -53,7 +53,7 @@ class BlacklistsController(rest.RestController):
|
|||||||
params, self.SORT_KEYS)
|
params, self.SORT_KEYS)
|
||||||
|
|
||||||
# Extract any filter params
|
# Extract any filter params
|
||||||
accepted_filters = ('pattern')
|
accepted_filters = ('pattern', )
|
||||||
criterion = self._apply_filter_params(
|
criterion = self._apply_filter_params(
|
||||||
params, accepted_filters, {})
|
params, accepted_filters, {})
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class TldsController(rest.RestController):
|
|||||||
params, self.SORT_KEYS)
|
params, self.SORT_KEYS)
|
||||||
|
|
||||||
# Extract any filter params.
|
# Extract any filter params.
|
||||||
accepted_filters = ('name')
|
accepted_filters = ('name', )
|
||||||
criterion = self._apply_filter_params(
|
criterion = self._apply_filter_params(
|
||||||
params, accepted_filters, {})
|
params, accepted_filters, {})
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import six
|
||||||
|
|
||||||
from designate.tests.test_api.test_v2 import ApiV2TestCase
|
from designate.tests.test_api.test_v2 import ApiV2TestCase
|
||||||
|
|
||||||
|
|
||||||
@ -127,3 +129,35 @@ class ApiV2BlacklistsTest(ApiV2TestCase):
|
|||||||
|
|
||||||
def test_update_bkaclist_invalid_id(self):
|
def test_update_bkaclist_invalid_id(self):
|
||||||
self._assert_invalid_uuid(self.client.patch_json, '/blacklists/%s')
|
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']))
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import six
|
||||||
|
|
||||||
from designate.tests.test_api.test_v2 import ApiV2TestCase
|
from designate.tests.test_api.test_v2 import ApiV2TestCase
|
||||||
|
|
||||||
|
|
||||||
@ -125,3 +127,33 @@ class ApiV2TldsTest(ApiV2TestCase):
|
|||||||
|
|
||||||
def test_update_tld_invalid_id(self):
|
def test_update_tld_invalid_id(self):
|
||||||
self._assert_invalid_uuid(self.client.patch_json, '/tlds/%s')
|
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']))
|
||||||
|
@ -275,7 +275,6 @@ Filtering
|
|||||||
Currently, the following attributes support filtering:
|
Currently, the following attributes support filtering:
|
||||||
|
|
||||||
* **Blacklists**: pattern
|
* **Blacklists**: pattern
|
||||||
* **Records**: data
|
|
||||||
* **Recordsets**: name, type, ttl, data, description, status
|
* **Recordsets**: name, type, ttl, data, description, status
|
||||||
* **TLDs**: name
|
* **TLDs**: name
|
||||||
* **Zones**: name, email, ttl, description, status
|
* **Zones**: name, email, ttl, description, status
|
||||||
|
Loading…
Reference in New Issue
Block a user