summaryrefslogtreecommitdiffstats
path: root/testapi
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2017-09-12 01:31:17 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-09-12 01:31:17 +0000
commit0a249a4a8047db77ea9a2eb44c847bf45c4b23cf (patch)
tree5aae31806f6504aa3fed474152f55ea867765b86 /testapi
parent800bd0ae7f3478c0f55ae52325b9da6355b985f2 (diff)
parentb1ef7b7f6f892763da375a72c0a4c1d9f4790db3 (diff)
Merge "add case-insensitive for find pods query"
Diffstat (limited to 'testapi')
-rw-r--r--testapi/.gitignore1
-rw-r--r--testapi/opnfv_testapi/common/check.py8
-rw-r--r--testapi/opnfv_testapi/tests/unit/fake_pymongo.py12
-rw-r--r--testapi/opnfv_testapi/tests/unit/resources/test_pod.py7
4 files changed, 24 insertions, 4 deletions
diff --git a/testapi/.gitignore b/testapi/.gitignore
index 86ec0d2..a3d6e01 100644
--- a/testapi/.gitignore
+++ b/testapi/.gitignore
@@ -5,3 +5,4 @@ opnfv_testapi/static
build
*.egg-info
3rd_party/static/static
+*.pyc
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 24ba876..acd3317 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import functools
+import re
from tornado import gen
from tornado import web
@@ -92,7 +93,12 @@ def new_not_exists(xstep):
def wrap(self, *args, **kwargs):
query = kwargs.get('query')
if query:
- to_data = yield dbapi.db_find_one(self.table, query())
+ query_data = query()
+ if self.table == 'pods':
+ if query_data.get('name') is not None:
+ query_data['name'] = re.compile(query_data.get('name'),
+ re.IGNORECASE)
+ to_data = yield dbapi.db_find_one(self.table, query_data)
if to_data:
raises.Forbidden(message.exist(self.table, query()))
ret = yield gen.coroutine(xstep)(self, *args, **kwargs)
diff --git a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py b/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
index 0ca83df..3320a86 100644
--- a/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -6,6 +6,8 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import re
+
from operator import itemgetter
from bson.objectid import ObjectId
@@ -190,8 +192,13 @@ class MemDb(object):
elif k == 'trust_indicator.current':
if content.get('trust_indicator').get('current') != v:
return False
- elif not isinstance(v, dict) and content.get(k, None) != v:
- return False
+ elif not isinstance(v, dict):
+ if isinstance(v, re._pattern_type):
+ if v.match(content.get(k, None)) is None:
+ return False
+ else:
+ if content.get(k, None) != v:
+ return False
return True
def _find(self, *args):
@@ -199,7 +206,6 @@ class MemDb(object):
for content in self.contents:
if self._in(content, *args):
res.append(content)
-
return res
def find(self, *args):
diff --git a/testapi/opnfv_testapi/tests/unit/resources/test_pod.py b/testapi/opnfv_testapi/tests/unit/resources/test_pod.py
index cb4f1d9..d1a19f7 100644
--- a/testapi/opnfv_testapi/tests/unit/resources/test_pod.py
+++ b/testapi/opnfv_testapi/tests/unit/resources/test_pod.py
@@ -21,6 +21,8 @@ class TestPodBase(base.TestBase):
self.req_d = pod_models.PodCreateRequest('zte-1', 'virtual',
'zte pod 1', 'ci-pod')
self.req_e = pod_models.PodCreateRequest('zte-2', 'metal', 'zte pod 2')
+ self.req_f = pod_models.PodCreateRequest('Zte-1', 'virtual',
+ 'zte pod 1', 'ci-pod')
self.get_res = pod_models.Pod
self.list_res = pod_models.Pods
self.basePath = '/api/v1/pods'
@@ -58,6 +60,11 @@ class TestPodCreate(TestPodBase):
self.create_d()
return self.req_d
+ @executor.create(httplib.FORBIDDEN, message.exist_base)
+ def test_alreadyExistCaseInsensitive(self):
+ self.create(self.req_f)
+ return self.req_d
+
class TestPodGet(TestPodBase):
def setUp(self):