diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-12-07 04:04:09 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2018-01-02 10:47:15 +0800 |
commit | f505dab1f5f26154619ec5c30cabbd8efaad173e (patch) | |
tree | 212e39f635abf72e41d5335be23895b31384c8f6 /testapi/opnfv_testapi/common | |
parent | 25345fc94b0cfa24df4fc37cf4aa6befeaefad59 (diff) |
leverage query_by_name decorator to simplify name querying
name query is case insensitive and partial match
Change-Id: I65a6f5d3aa9411559cb9cf27d0fbd7ec46d4b26f
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/common')
-rw-r--r-- | testapi/opnfv_testapi/common/check.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py index 8a76f17..713f0fb 100644 --- a/testapi/opnfv_testapi/common/check.py +++ b/testapi/opnfv_testapi/common/check.py @@ -158,3 +158,17 @@ def updated_one_not_exist(xstep): ret = yield gen.coroutine(xstep)(self, data, *args, **kwargs) raise gen.Return(ret) return wrap + + +def query_by_name(xstep): + @functools.wraps(xstep) + def wrap(self, *args, **kwargs): + if 'name' in self.request.query_arguments.keys(): + query = kwargs.get('query', {}) + query.update({'name': re.compile(self.get_query_argument('name'), re.IGNORECASE)}) + kwargs.update({'query': query}) + + ret = yield gen.coroutine(xstep)(self, *args, **kwargs) + raise gen.Return(ret) + + return wrap |