Merge "Enable filter on blacklists & tlds"

This commit is contained in:
Jenkins 2015-07-09 11:20:55 +00:00 committed by Gerrit Code Review
commit 5f9abc0669
5 changed files with 68 additions and 3 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,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