summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests/unit/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/opnfv_testapi/tests/unit/handlers')
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_base.py11
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_deploy_result.py17
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_pod.py40
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_project.py21
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_result.py85
-rw-r--r--testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py40
6 files changed, 121 insertions, 93 deletions
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_base.py b/testapi/opnfv_testapi/tests/unit/handlers/test_base.py
index 6436b8b..1fd3324 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_base.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_base.py
@@ -35,20 +35,21 @@ class TestBase(testing.AsyncHTTPTestCase):
details='zte pod 1',
role='community-ci',
_id=str(ObjectId()),
- owner='ValidUser',
+ creator='ValidUser',
creation_date=str(datetime.now()))
self.pod_e = pod_models.Pod(name='zte-pod2',
mode='metal',
details='zte pod 2',
role='production-ci',
_id=str(ObjectId()),
- owner='ValidUser',
+ creator='ValidUser',
creation_date=str(datetime.now()))
self.project_e = project_models.Project(
name='functest',
description='functest test',
+ creator='ValidUser',
_id=str(ObjectId()),
- create_date=str(datetime.now()))
+ creation_date=str(datetime.now()))
self.req_d = None
self.req_e = None
@@ -62,7 +63,8 @@ class TestBase(testing.AsyncHTTPTestCase):
'opnfv-gerrit-functest-submitters',
'opnfv-gerrit-qtip-submitters',
'opnfv-gerrit-qtip-contributors',
- 'opnfv-gerrit-apex-submitters']
+ 'opnfv-gerrit-apex-submitters',
+ 'opnfv-gerrit-noProject-submitters']
})
def tearDown(self):
@@ -157,7 +159,6 @@ class TestBase(testing.AsyncHTTPTestCase):
res = self.fetch(url,
method='DELETE',
headers=self.headers)
-
return res.code, res.body
def delete(self, *args):
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_deploy_result.py b/testapi/opnfv_testapi/tests/unit/handlers/test_deploy_result.py
index 65e765e..8f2ca76 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_deploy_result.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_deploy_result.py
@@ -92,6 +92,10 @@ class DeployResultGet(DeployResultBase):
self.req_d_id = self._create_d()
self.req_10d_later = self._create_changed_date(days=10)
+ @executor.get(httplib.OK, 'assert_res')
+ def test_getOne(self):
+ return self.req_d_id
+
@executor.query(httplib.OK, '_query_success', 3)
def test_queryInstaller(self):
return self._set_query('installer')
@@ -165,6 +169,19 @@ class DeployResultGet(DeployResultBase):
self._create_error_start_date('')
return self._set_query(period=5)
+ @executor.query(httplib.OK, '_query_success', 0)
+ def test_notFound(self):
+ return self._set_query('installer',
+ 'version',
+ 'job_name',
+ 'build_id',
+ 'scenario',
+ 'upstream_job_name',
+ 'upstream_build_id',
+ 'criteria',
+ pod='notExistPod',
+ period=1)
+
def _query_success(self, body, number):
self.assertEqual(number, len(body.deployresults))
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py
index 2818513..3a16799 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,11 +24,13 @@ 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:
req = self.req_d
- self.assertEqual(pod, pm.Pod(owner='ValidUser', **req.format()))
+ self.assertEqual(pod, pm.Pod(creator='ValidUser', **req.format()))
self.assertIsNotNone(pod.creation_date)
self.assertIsNotNone(pod._id)
@@ -101,3 +104,38 @@ 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_project.py b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py
index cbd1a4e..5903507 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_project.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py
@@ -12,6 +12,7 @@ import urllib
from opnfv_testapi.common import message
from opnfv_testapi.models import project_models
+from opnfv_testapi.models import testcase_models as tcm
from opnfv_testapi.tests.unit import executor
from opnfv_testapi.tests.unit.handlers import test_base as base
@@ -23,6 +24,9 @@ class TestProjectBase(base.TestBase):
'qtip-ssh test')
self.req_e = project_models.ProjectCreateRequest('functest',
'functest test')
+ self.testcase_d = tcm.TestcaseCreateRequest.from_dict(
+ self.load_json('testcase_d'))
+ self.project = 'qtip'
self.get_res = project_models.Project
self.list_res = project_models.Projects
self.update_res = project_models.Project
@@ -150,6 +154,15 @@ class TestProjectUpdate(TestProjectBase):
return self.req_d, self.req_d.name
@executor.mock_valid_lfid()
+ @executor.update(httplib.UNAUTHORIZED, message.tied_with_resource())
+ def test_updateNotAllowed(self):
+ self.create_help('/api/v1/projects/%s/cases',
+ self.testcase_d,
+ self.req_d.name)
+ req = project_models.ProjectUpdateRequest('apex', 'apex test')
+ return req, self.req_d.name
+
+ @executor.mock_valid_lfid()
@executor.update(httplib.OK, '_assert_update')
def test_success(self):
req = project_models.ProjectUpdateRequest('apex', 'apex test')
@@ -178,6 +191,14 @@ class TestProjectDelete(TestProjectBase):
return 'notFound'
@executor.mock_valid_lfid()
+ @executor.delete(httplib.UNAUTHORIZED, message.tied_with_resource())
+ def test_deleteNotAllowed(self):
+ self.create_help('/api/v1/projects/%s/cases',
+ self.testcase_d,
+ self.req_d.name)
+ return self.req_d.name
+
+ @executor.mock_valid_lfid()
@executor.delete(httplib.OK, '_assert_delete')
def test_success(self):
return self.req_d.name
diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_result.py b/testapi/opnfv_testapi/tests/unit/handlers/test_result.py
index f1f055e..6435367 100644
--- a/testapi/opnfv_testapi/tests/unit/handlers/test_result.py
+++ b/testapi/opnfv_testapi/tests/unit/handlers/test_result.py
@@ -10,7 +10,6 @@ import copy
from datetime import datetime
from datetime import timedelta
import httplib
-import json
import urllib
from opnfv_testapi.common import message
@@ -34,8 +33,9 @@ class TestResultBase(base.TestBase):
self.basePath = '/api/v1/results'
fake_pymongo.pods.insert({'name': self.req_d.pod_name})
fake_pymongo.projects.insert({'name': self.req_d.project_name})
- fake_pymongo.testcases.insert({'name': self.req_d.case_name,
- 'project_name': self.req_d.project_name})
+ fake_pymongo.testcases.insert({
+ 'name': self.req_d.case_name,
+ 'project_name': self.req_d.project_name})
def assert_res(self, result, req=None):
if req is None:
@@ -46,22 +46,6 @@ class TestResultBase(base.TestBase):
_, res = self.create_d()
return res.href.split('/')[-1]
- def upload(self, req):
- if req and not isinstance(req, str) and hasattr(req, 'format'):
- req = req.format()
- res = self.fetch(self.basePath + '/upload',
- method='POST',
- body=json.dumps(req),
- headers=self.headers)
-
- return self._get_return(res, self.create_res)
-
-
-class TestResultUpload(TestResultBase):
- @executor.upload(httplib.BAD_REQUEST, message.key_error('file'))
- def test_filenotfind(self):
- return None
-
class TestResultCreate(TestResultBase):
@executor.create(httplib.BAD_REQUEST, message.no_body())
@@ -121,18 +105,6 @@ class TestResultCreate(TestResultBase):
req.details = {'1.name': 'dot_name'}
return req
- @executor.create(httplib.OK, '_assert_no_ti')
- def test_no_ti(self):
- req = copy.deepcopy(self.req_d)
- req.trust_indicator = rm.TI(0)
- self.actual_req = req
- return req
-
- def _assert_no_ti(self, body):
- _id = body.href.split('/')[-1]
- code, body = self.get(_id)
- self.assert_res(body, self.actual_req)
-
class TestResultGet(TestResultBase):
def setUp(self):
@@ -174,10 +146,6 @@ class TestResultGet(TestResultBase):
return self._set_query('scenario')
@executor.query(httplib.OK, '_query_success', 3)
- def test_queryTrustIndicator(self):
- return self._set_query('trust_indicator')
-
- @executor.query(httplib.OK, '_query_success', 3)
def test_queryCriteria(self):
return self._set_query('criteria')
@@ -197,16 +165,6 @@ class TestResultGet(TestResultBase):
def test_queryLast(self):
return self._set_query(last=1)
- @executor.query(httplib.OK, '_query_success', 4)
- def test_queryPublic(self):
- self._create_public_data()
- return self._set_query()
-
- @executor.query(httplib.OK, '_query_success', 1)
- def test_queryPrivate(self):
- self._create_private_data()
- return self._set_query(public='false')
-
@executor.query(httplib.OK, '_query_period_one', 1)
def test_combination(self):
return self._set_query('pod',
@@ -216,7 +174,6 @@ class TestResultGet(TestResultBase):
'installer',
'build_tag',
'scenario',
- 'trust_indicator',
'criteria',
period=5)
@@ -228,7 +185,6 @@ class TestResultGet(TestResultBase):
'installer',
'build_tag',
'scenario',
- 'trust_indicator',
'criteria',
pod='notExistPod',
period=1)
@@ -266,24 +222,10 @@ class TestResultGet(TestResultBase):
self.create(req)
return req
- def _create_public_data(self, **kwargs):
- req = copy.deepcopy(self.req_d)
- req.public = 'true'
- self.create(req)
- return req
-
- def _create_private_data(self, **kwargs):
- req = copy.deepcopy(self.req_d)
- req.public = 'false'
- self.create(req)
- return req
-
def _set_query(self, *args, **kwargs):
def get_value(arg):
if arg in ['pod', 'project', 'case']:
return getattr(self.req_d, arg + '_name')
- elif arg == 'trust_indicator':
- return self.req_d.trust_indicator.current
else:
return getattr(self.req_d, arg)
@@ -293,24 +235,3 @@ class TestResultGet(TestResultBase):
for k, v in kwargs.iteritems():
query.append((k, v))
return urllib.urlencode(query)
-
-
-class TestResultUpdate(TestResultBase):
- def setUp(self):
- super(TestResultUpdate, self).setUp()
- self.req_d_id = self._create_d()
-
- @executor.update(httplib.OK, '_assert_update_ti')
- def test_success(self):
- update_date = str(datetime.now() + timedelta(days=1))
- update_step = -0.05
- self.after_update = copy.deepcopy(self.req_d)
- self.after_update.trust_indicator.current += update_step
- self.after_update.trust_indicator.histories.append(
- rm.TIHistory(update_date, update_step))
- update = rm.ResultUpdateRequest(
- trust_indicator=self.after_update.trust_indicator)
- return update, self.req_d_id
-
- def _assert_update_ti(self, request, body):
- self.assert_res(body, self.after_update)
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, '')