summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py')
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py b/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py
index 9a2bf58..e0ce381 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
@@ -31,7 +32,8 @@ class TestCaseBase(base.TestBase):
self.update_res = tcm.Testcase
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:
@@ -69,8 +71,8 @@ class TestCaseBase(base.TestBase):
return super(TestCaseBase, self).update(new, self.project, case)
@executor.mock_valid_lfid()
- def delete(self, case):
- return super(TestCaseBase, self).delete(self.project, case)
+ def delete(self, case=None, project=None):
+ return super(TestCaseBase, self).delete(project, case)
class TestCaseCreate(TestCaseBase):
@@ -78,6 +80,11 @@ class TestCaseCreate(TestCaseBase):
def test_noBody(self):
return None
+ @executor.create(httplib.FORBIDDEN, message.no_permission())
+ def test_unauthorized(self):
+ self.project = 'newProject'
+ return self.req_d
+
@executor.create(httplib.FORBIDDEN, message.not_found_base)
def test_noProject(self):
self.project = 'noProject'
@@ -151,6 +158,12 @@ class TestCaseUpdate(TestCaseBase):
self.create_e()
return self.update_req, self.req_d.name
+ @executor.update(httplib.FORBIDDEN, message.no_permission())
+ def test_unauthorized(self):
+ update_req_e = tcm.TestcaseUpdateRequest(project_name="newProject",
+ **self.req_e.format())
+ return update_req_e, self.req_d.name
+
@executor.update(httplib.FORBIDDEN, message.no_update())
def test_noUpdate(self):
update = tcm.TestcaseUpdateRequest(project_name=self.project,
@@ -176,14 +189,31 @@ 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})
+ fake_pymongo.testcases.insert({
+ 'name': 'newCase',
+ 'project_name': 'newProject'})
@executor.delete(httplib.NOT_FOUND, message.not_found_base)
def test_notFound(self):
- return 'notFound'
+ return 'notFound', self.project
+
+ @executor.delete(httplib.FORBIDDEN, message.no_permission())
+ def test_unauthorized(self):
+ return 'newCase', 'newProject'
+
+ @executor.delete(httplib.UNAUTHORIZED, message.tied_with_resource())
+ def test_deleteNotAllowed(self):
+ self.create_help('/api/v1/results', self.results_d)
+ return self.results_d.case_name, self.project
@executor.delete(httplib.OK, '_delete_success')
def test_success(self):
- return self.req_d.name
+ return self.req_d.name, self.project
def _delete_success(self, body):
self.assertEqual(body, '')