Added 'add_filters' to ClientMixin for GET vars
This adds the ability to filter collections via the add_filters method on the ClientMixin class. It takes a filters dict and adds those filters to the URL. Added to all functionaltests clients. Change-Id: Ia4a6eb6bf2d3aa84e02420645975bc4207b0f09a
This commit is contained in:
parent
86f85d085a
commit
6fa9c93796
@ -22,15 +22,18 @@ from functionaltests.common.client import ClientMixin
|
||||
class BlacklistClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def blacklists_uri(cls):
|
||||
return "/v2/blacklists"
|
||||
def blacklists_uri(cls, filters=None):
|
||||
url = "/v2/blacklists"
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def blacklist_uri(cls, blacklist_id):
|
||||
return "{0}/{1}".format(cls.blacklists_uri(), blacklist_id)
|
||||
|
||||
def list_blacklists(self, **kwargs):
|
||||
resp, body = self.client.get(self.blacklists_uri(), **kwargs)
|
||||
def list_blacklists(self, filters=None, **kwargs):
|
||||
resp, body = self.client.get(self.blacklists_uri(filters), **kwargs)
|
||||
return self.deserialize(resp, body, BlacklistListModel)
|
||||
|
||||
def get_blacklist(self, blacklist_id, **kwargs):
|
||||
|
@ -22,15 +22,18 @@ from functionaltests.common.client import ClientMixin
|
||||
class PoolClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def pools_uri(cls):
|
||||
return "/v2/pools"
|
||||
def pools_uri(cls, filters=None):
|
||||
url = "/v2/pools"
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def pool_uri(cls, pool_id):
|
||||
return "{0}/{1}".format(cls.pools_uri(), pool_id)
|
||||
|
||||
def list_pools(self, **kwargs):
|
||||
resp, body = self.client.get(self.pools_uri(), **kwargs)
|
||||
def list_pools(self, filters=None, **kwargs):
|
||||
resp, body = self.client.get(self.pools_uri(filters), **kwargs)
|
||||
return self.deserialize(resp, body, PoolListModel)
|
||||
|
||||
def get_pool(self, pool_id, **kwargs):
|
||||
|
@ -21,11 +21,15 @@ from functionaltests.common.client import ClientMixin
|
||||
class QuotasClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def quotas_uri(cls, tenant_id):
|
||||
return "/admin/quotas/" + tenant_id
|
||||
def quotas_uri(cls, tenant_id, filters=None):
|
||||
url = "/admin/quotas/{0}".format(tenant_id)
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
def get_quotas(self, tenant_id, **kwargs):
|
||||
resp, body = self.client.get(self.quotas_uri(tenant_id), **kwargs)
|
||||
def get_quotas(self, tenant_id, filters=None, **kwargs):
|
||||
resp, body = self.client.get(
|
||||
self.quotas_uri(tenant_id, filters), **kwargs)
|
||||
return self.deserialize(resp, body, QuotasModel)
|
||||
|
||||
def patch_quotas(self, tenant_id, quotas_model, **kwargs):
|
||||
|
@ -25,15 +25,19 @@ from functionaltests.common import utils
|
||||
class RecordsetClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def recordsets_uri(cls, zone_id):
|
||||
return "/v2/zones/{0}/recordsets".format(zone_id)
|
||||
def recordsets_uri(cls, zone_id, filters=None):
|
||||
url = "/v2/zones/{0}/recordsets".format(zone_id)
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def recordset_uri(cls, zone_id, recordset_id):
|
||||
return "{0}/{1}".format(cls.recordsets_uri(zone_id), recordset_id)
|
||||
|
||||
def list_recordsets(self, zone_id, **kwargs):
|
||||
resp, body = self.client.get(self.recordsets_uri(zone_id), **kwargs)
|
||||
def list_recordsets(self, zone_id, filters=None, **kwargs):
|
||||
resp, body = self.client.get(
|
||||
self.recordsets_uri(zone_id, filters), **kwargs)
|
||||
return self.deserialize(resp, body, RecordsetListModel)
|
||||
|
||||
def get_recordset(self, zone_id, recordset_id, **kwargs):
|
||||
|
@ -25,15 +25,18 @@ from functionaltests.common import utils
|
||||
class ZoneClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def zones_uri(cls):
|
||||
return "/v2/zones"
|
||||
def zones_uri(cls, filters=None):
|
||||
url = "/v2/zones"
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def zone_uri(cls, id):
|
||||
return "{0}/{1}".format(cls.zones_uri(), id)
|
||||
|
||||
def list_zones(self, **kwargs):
|
||||
resp, body = self.client.get(self.zones_uri(), **kwargs)
|
||||
def list_zones(self, filters=None, **kwargs):
|
||||
resp, body = self.client.get(self.zones_uri(filters), **kwargs)
|
||||
return self.deserialize(resp, body, ZoneListModel)
|
||||
|
||||
def get_zone(self, id, **kwargs):
|
||||
|
@ -22,15 +22,19 @@ from functionaltests.common import utils
|
||||
class ZoneImportClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def zone_imports_uri(cls):
|
||||
return "/v2/zones/tasks/imports"
|
||||
def zone_imports_uri(cls, filters=None):
|
||||
url = "/v2/zones/tasks/imports"
|
||||
if filters:
|
||||
url = cls.add_filters(url, filters)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def zone_import_uri(cls, id):
|
||||
return "{0}/{1}".format(cls.zone_imports_uri(), id)
|
||||
|
||||
def list_zone_imports(self, **kwargs):
|
||||
resp, body = self.client.get(self.zone_imports_uri(), **kwargs)
|
||||
def list_zone_imports(self, filters=None, **kwargs):
|
||||
resp, body = self.client.get(
|
||||
self.zone_imports_uri(filters), **kwargs)
|
||||
return self.deserialize(resp, body, ZoneImportListModel)
|
||||
|
||||
def get_zone_import(self, id, **kwargs):
|
||||
|
@ -18,6 +18,7 @@ import abc
|
||||
|
||||
from config import cfg
|
||||
from noauth import NoAuthAuthProvider
|
||||
from six.moves.urllib import parse
|
||||
from tempest_lib.common.rest_client import RestClient
|
||||
from tempest_lib.auth import KeystoneV2Credentials
|
||||
from tempest_lib.auth import KeystoneV2AuthProvider
|
||||
@ -136,3 +137,28 @@ class ClientMixin(object):
|
||||
@property
|
||||
def tenant_id(self):
|
||||
return self.client.tenant_id
|
||||
|
||||
@classmethod
|
||||
def add_filters(cls, url, filters):
|
||||
"""
|
||||
:param url: base URL for the request
|
||||
:param filters: dict with var:val pairs to add as parameters to URL
|
||||
"""
|
||||
first = True
|
||||
for f in filters:
|
||||
try:
|
||||
filters[f] = parse.quote_plus(filters[f])
|
||||
|
||||
# This is a unicode character and we need to UTF-8 encode it first
|
||||
except KeyError:
|
||||
filters[f] = parse.quote_plus(filters[f].encode('utf-8'))
|
||||
|
||||
# This is an integer, or something else we don't want to quote
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
url = '{url}{sep}{var}={val}'.format(
|
||||
url=url, sep=('?' if first else '&'), var=f, val=filters[f]
|
||||
)
|
||||
first = False
|
||||
return url
|
||||
|
Loading…
x
Reference in New Issue
Block a user