summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests/unit/handlers
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2018-03-01 07:28:45 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-01 07:28:45 +0000
commit3fd0a832c8f8c1fb55a23f137e0b442084d36363 (patch)
tree3d4a94227e7658cff47fc594ae28e60893fa7f05 /testapi/opnfv_testapi/tests/unit/handlers
parent788d670037a77b35148551ebecf1314146e5a4b7 (diff)
parent4aa95918da586d3c1f9bf19a19c5cd55541c38d0 (diff)
Merge "Prevent to delete the pods"
Diffstat (limited to 'testapi/opnfv_testapi/tests/unit/handlers')
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_pod.py37
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py12
2 files changed, 49 insertions, 0 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py
index d1eedc0..28d29b5 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py
@@ -10,6 +10,7 @@ import httplib
from opnfv_testapi.common import message
from opnfv_testapi.models import pod_models as pm
+from opnfv_testapi.models import result_models as rm
from opnfv_testapi.tests.unit import executor
from opnfv_testapi.tests.unit import fake_pymongo
from opnfv_testapi.tests.unit.handlers import test_base as base
@@ -23,6 +24,8 @@ class TestPodBase(base.TestBase):
self.basePath = '/api/v1/pods'
self.req_d = pm.PodCreateRequest.from_dict(self.pod_d.format())
self.req_e = pm.PodCreateRequest.from_dict(self.pod_e.format())
+ self.results_d = rm.ResultCreateRequest.from_dict(
+ self.load_json('test_result'))
def assert_get_body(self, pod, req=None):
if not req:
@@ -101,3 +104,37 @@ class TestPodGet(TestPodBase):
self.assert_get_body(pod)
else:
self.assert_get_body(pod, self.req_e)
+
+
+class TestPodDelete(TestPodBase):
+ @executor.mock_valid_lfid()
+ def setUp(self):
+ super(TestPodDelete, self).setUp()
+ fake_pymongo.pods.insert(self.pod_d.format())
+ fake_pymongo.projects.insert({'name': self.results_d.project_name})
+ fake_pymongo.testcases.insert({'name': self.results_d.case_name,
+ 'project_name': self.results_d.project_name})
+
+ @executor.delete(httplib.BAD_REQUEST, message.not_login())
+ def test_notlogin(self):
+ return self.pod_d.name
+
+ @executor.delete(httplib.NOT_FOUND, message.not_found_base)
+ def test_notFound(self):
+ return 'notFound'
+
+ @executor.mock_valid_lfid()
+ @executor.delete(httplib.UNAUTHORIZED, message.tied_with_resource())
+ def test_deleteNotAllowed(self):
+ self.create_help('/api/v1/results', self.results_d)
+ return self.pod_d.name
+
+ @executor.mock_valid_lfid()
+ @executor.delete(httplib.OK, '_assert_delete')
+ def test_success(self):
+ return self.pod_d.name
+
+ def _assert_delete(self, body):
+ self.assertEqual(body, '')
+ code, body = self.get(self.pod_d.name)
+ self.assertEqual(code, httplib.NOT_FOUND)
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py b/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py
index 9a2bf58..78f3ab1 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py
@@ -10,6 +10,7 @@ import httplib
from opnfv_testapi.common import message
from opnfv_testapi.models import testcase_models as tcm
+from opnfv_testapi.models import result_models as rm
from opnfv_testapi.tests.unit import executor
from opnfv_testapi.tests.unit import fake_pymongo
from opnfv_testapi.tests.unit.handlers import test_base as base
@@ -32,6 +33,8 @@ class TestCaseBase(base.TestBase):
self.basePath = '/api/v1/projects/%s/cases'
fake_pymongo.projects.insert(self.project_e.format())
print self.req_d.format()
+ self.results_d = rm.ResultCreateRequest.from_dict(
+ self.load_json('test_result'))
def assert_body(self, case, req=None):
if not req:
@@ -176,11 +179,20 @@ class TestCaseDelete(TestCaseBase):
def setUp(self):
super(TestCaseDelete, self).setUp()
self.create_d()
+ fake_pymongo.pods.insert(self.pod_d.format())
+ fake_pymongo.projects.insert({'name': self.results_d.project_name})
+ fake_pymongo.testcases.insert({'name': self.results_d.case_name,
+ 'project_name': self.results_d.project_name})
@executor.delete(httplib.NOT_FOUND, message.not_found_base)
def test_notFound(self):
return 'notFound'
+ @executor.delete(httplib.UNAUTHORIZED, message.tied_with_resource())
+ def test_deleteNotAllowed(self):
+ print self.create_help('/api/v1/results', self.results_d)
+ return self.results_d.case_name
+
@executor.delete(httplib.OK, '_delete_success')
def test_success(self):
return self.req_d.name