diff options
Diffstat (limited to 'testapi/opnfv_testapi')
7 files changed, 41 insertions, 19 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py index 77b48f5..18dc67d 100644 --- a/testapi/opnfv_testapi/common/check.py +++ b/testapi/opnfv_testapi/common/check.py @@ -21,7 +21,8 @@ from opnfv_testapi.db import api as dbapi def is_authorized(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): - if CONF.api_authenticate and self.table in ['pods', 'projects', 'testcases', 'scenarios']: + resources = ['pods', 'projects', 'testcases', 'scenarios'] + if CONF.api_authenticate and self.table in resources: testapi_id = self.get_secure_cookie(constants.TESTAPI_ID) if not testapi_id: raises.Unauthorized(message.not_login()) @@ -51,18 +52,19 @@ def is_reource_tied(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): query_data = {} - tied_map_tables = { + tied_maps = { 'projects': ('testcases', 'project_name'), 'pods': ('results', 'pod_name'), 'testcases': ('results', 'case_name') } - if self.table in tied_map_tables: + if self.table in tied_maps: if method.__name__ == '_update': if 'name' not in self.json_args: ret = yield gen.coroutine(method)(self, *args, **kwargs) raise gen.Return(ret) - query_data[tied_map_tables[self.table][1]] = kwargs.get('query')['name'] - data = yield dbapi.db_find_one(tied_map_tables[self.table][0], query_data) + query_data[tied_maps[self.table][1]] = kwargs.get('query')['name'] + data = yield dbapi.db_find_one(tied_maps[self.table][0], + query_data) if data: raises.Unauthorized(message.tied_with_resource()) ret = yield gen.coroutine(method)(self, *args, **kwargs) @@ -159,8 +161,10 @@ def new_not_exists(xstep): if query: query_data = query() if self.table == 'pods': - if query_data.get('name') is not None: - query_data['name'] = re.compile('\\b' + query_data.get('name') + '\\b', re.IGNORECASE) + if query_data.get('name'): + query_data['name'] = re.compile( + '\\b{}\\b'.format(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())) @@ -188,7 +192,9 @@ def query_by_name(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)}) + query.update({ + 'name': re.compile(self.get_query_argument('name'), + re.IGNORECASE)}) kwargs.update({'query': query}) ret = yield gen.coroutine(xstep)(self, *args, **kwargs) diff --git a/testapi/opnfv_testapi/models/project_models.py b/testapi/opnfv_testapi/models/project_models.py index eac2fd3..5c8c048 100644 --- a/testapi/opnfv_testapi/models/project_models.py +++ b/testapi/opnfv_testapi/models/project_models.py @@ -27,7 +27,11 @@ class ProjectUpdateRequest(base_models.ModelBase): @swagger.model() class Project(base_models.ModelBase): def __init__(self, - name=None, creator='', _id=None, description=None, creation_date=None): + name=None, + creator='', + _id=None, + description=None, + creation_date=None): self.creator = creator self._id = _id self.name = name diff --git a/testapi/opnfv_testapi/models/scenario_models.py b/testapi/opnfv_testapi/models/scenario_models.py index 01b5c2b..537650e 100644 --- a/testapi/opnfv_testapi/models/scenario_models.py +++ b/testapi/opnfv_testapi/models/scenario_models.py @@ -178,11 +178,16 @@ class Scenario(base_models.ModelBase): @property installers: @ptype installers: C{list} of L{ScenarioInstaller} """ - def __init__(self, name='', create_date='', _id='', creator='', installers=None): + def __init__(self, + name='', + creation_date='', + _id='', + creator='', + installers=None): self.name = name self.creator = creator self._id = _id - self.creation_date = create_date + self.creation_date = creation_date self.installers = list_default(installers) @staticmethod diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py index 28d29b5..3a16799 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_pod.py @@ -112,8 +112,9 @@ class TestPodDelete(TestPodBase): 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}) + 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): diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_project.py b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py index 884dd68..5903507 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_project.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_project.py @@ -156,7 +156,9 @@ class TestProjectUpdate(TestProjectBase): @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) + 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 @@ -191,7 +193,9 @@ class TestProjectDelete(TestProjectBase): @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) + self.create_help('/api/v1/projects/%s/cases', + self.testcase_d, + self.req_d.name) return self.req_d.name @executor.mock_valid_lfid() diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_result.py b/testapi/opnfv_testapi/tests/unit/handlers/test_result.py index c07d792..892256a 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_result.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_result.py @@ -33,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: diff --git a/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py b/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py index 78f3ab1..97325e2 100644 --- a/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py +++ b/testapi/opnfv_testapi/tests/unit/handlers/test_testcase.py @@ -181,8 +181,9 @@ class TestCaseDelete(TestCaseBase): 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': 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): |