summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testapi/docker/Dockerfile6
-rw-r--r--testapi/opnfv_testapi/common/check.py14
-rw-r--r--testapi/opnfv_testapi/handlers/base_handlers.py8
-rw-r--r--testapi/opnfv_testapi/handlers/pod_handlers.py11
-rw-r--r--testapi/opnfv_testapi/handlers/project_handlers.py11
-rw-r--r--testapi/opnfv_testapi/tests/unit/fake_pymongo.py3
6 files changed, 28 insertions, 25 deletions
diff --git a/testapi/docker/Dockerfile b/testapi/docker/Dockerfile
index 25deb26..33088c7 100644
--- a/testapi/docker/Dockerfile
+++ b/testapi/docker/Dockerfile
@@ -47,5 +47,11 @@ RUN git clone https://gerrit.opnfv.org/gerrit/releng-testresults /home/releng-te
WORKDIR /home/releng-testresults/testapi
RUN pip install -r requirements.txt
+
+# bugfix
+# SSLError: hostname 'identity.linuxfoundation.org' doesn't match 'c.sni.fastly.net'
+# hope it is a temprary, try to fix it in upstream python-cas lib
+RUN sed -i '152,152s/)/,\ verify=False)/g' /usr/local/lib/python2.7/dist-packages/cas.py
+
RUN python setup.py install
CMD ["bash", "docker/start-server.sh"]
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 5dfbc75..333871d 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
diff --git a/testapi/opnfv_testapi/handlers/base_handlers.py b/testapi/opnfv_testapi/handlers/base_handlers.py
index 8c585a1..9eac737 100644
--- a/testapi/opnfv_testapi/handlers/base_handlers.py
+++ b/testapi/opnfv_testapi/handlers/base_handlers.py
@@ -104,7 +104,8 @@ class GenericApiHandler(web.RequestHandler):
@web.asynchronous
@gen.coroutine
- def _list(self, query=None, res_op=None, *args, **kwargs):
+ @check.query_by_name
+ def _list(self, query=None, **kwargs):
sort = kwargs.get('sort')
page = kwargs.get('page', 0)
last = kwargs.get('last', 0)
@@ -132,10 +133,7 @@ class GenericApiHandler(web.RequestHandler):
cursor = dbapi.db_aggregate(self.table, pipelines)
while (yield cursor.fetch_next):
data.append(self.format_data(cursor.next_object()))
- if res_op is None:
- res = {self.table: data}
- else:
- res = res_op(data, *args)
+ res = {self.table: data}
if page > 0:
res.update({
'pagination': {
diff --git a/testapi/opnfv_testapi/handlers/pod_handlers.py b/testapi/opnfv_testapi/handlers/pod_handlers.py
index 06a8b17..03c2033 100644
--- a/testapi/opnfv_testapi/handlers/pod_handlers.py
+++ b/testapi/opnfv_testapi/handlers/pod_handlers.py
@@ -6,7 +6,6 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import re
from opnfv_testapi.handlers import base_handlers
from opnfv_testapi.models import pod_models
@@ -19,14 +18,6 @@ class GenericPodHandler(base_handlers.GenericApiHandler):
self.table = 'pods'
self.table_cls = pod_models.Pod
- def set_query(self):
- query = dict()
- for k in self.request.query_arguments.keys():
- v = self.get_query_argument(k)
- if k == 'name':
- query['name'] = re.compile(v, re.IGNORECASE)
- return query
-
class PodCLHandler(GenericPodHandler):
@swagger.operation(nickname='listAllPods')
@@ -40,7 +31,7 @@ class PodCLHandler(GenericPodHandler):
@in name: query
@required name: False
"""
- self._list(query=self.set_query())
+ self._list()
@swagger.operation(nickname='createPod')
def post(self):
diff --git a/testapi/opnfv_testapi/handlers/project_handlers.py b/testapi/opnfv_testapi/handlers/project_handlers.py
index 3ba1a80..0800ee8 100644
--- a/testapi/opnfv_testapi/handlers/project_handlers.py
+++ b/testapi/opnfv_testapi/handlers/project_handlers.py
@@ -6,7 +6,6 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import re
from opnfv_testapi.handlers import base_handlers
from opnfv_testapi.models import project_models
@@ -21,14 +20,6 @@ class GenericProjectHandler(base_handlers.GenericApiHandler):
self.table = 'projects'
self.table_cls = project_models.Project
- def set_query(self):
- query = dict()
- for k in self.request.query_arguments.keys():
- v = self.get_query_argument(k)
- if k == 'name':
- query['name'] = re.compile(v, re.IGNORECASE)
- return query
-
class ProjectCLHandler(GenericProjectHandler):
@swagger.operation(nickname="listProjects")
@@ -47,7 +38,7 @@ class ProjectCLHandler(GenericProjectHandler):
@in name: query
@required name: False
"""
- self._list(query=self.set_query())
+ self._list()
@swagger.operation(nickname="createProject")
def post(self):
diff --git a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py b/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
index 7f4fd3e..041e6e8 100644
--- a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -178,6 +178,9 @@ class MemDb(object):
elif i_k == 'versions.projects.project':
return self._in_scenarios_project(i_v,
content)
+ elif isinstance(v, re._pattern_type):
+ if v.match(content.get(k, None)) is None:
+ return False
elif content.get(k, None) != v:
return False