class TestProjectCreate(TestProjectBase): @executor.create(httplib.BAD_REQUEST, message.not_login()) def test_notlogin(self): return self.req_d @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): return None @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): return project_models.ProjectCreateRequest('') @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): return project_models.ProjectCreateRequest(None) @executor.mock_valid_lfid() @executor.create(httplib.OK, 'assert_create_body') def test_success(self): return self.req_d @executor.mock_valid_lfid() @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExist(self): self.create_d() return self.req_d
class TestProjectDelete(TestProjectBase): @executor.mock_valid_lfid() def setUp(self): super(TestProjectDelete, self).setUp() self.create_d() @executor.delete(httplib.BAD_REQUEST, message.not_login()) def test_notlogin(self): return self.req_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/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 def _assert_delete(self, body): self.assertEqual(body, '') code, body = self.get(self.req_d.name) self.assertEqual(code, httplib.NOT_FOUND)
def wrapper(self, *args, **kwargs): if CONF.api_authenticate and self.table in [ 'pods', 'projects', 'testcases', 'scenarios' ]: testapi_id = self.get_secure_cookie(constants.TESTAPI_ID) if not testapi_id: raises.Unauthorized(message.not_login()) user_info = yield dbapi.db_find_one('users', {'user': testapi_id}) if not user_info: raises.Unauthorized(message.not_lfid()) if method.__name__ == "_create": kwargs['owner'] = testapi_id if self.table in ['projects']: query = kwargs.get('query') if type(query) is not dict: query_data = query() else: if self.json_args is None: query_data = query else: query_data = self.json_args group = "opnfv-gerrit-" + query_data['name'] + "-submitters" if group not in user_info['groups']: raises.Unauthorized(message.no_permission()) ret = yield gen.coroutine(method)(self, *args, **kwargs) raise gen.Return(ret)
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)
class TestProjectUpdate(TestProjectBase): @executor.mock_valid_lfid() def setUp(self): super(TestProjectUpdate, self).setUp() _, d_body = self.create_d() _, get_res = self.get(self.req_d.name) self.index_d = get_res._id self.create_e() @executor.update(httplib.BAD_REQUEST, message.not_login()) def test_notlogin(self): req = project_models.ProjectUpdateRequest('apex', 'apex test') return req, self.req_d.name @executor.update(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): return None, 'noBody' @executor.mock_valid_lfid() @executor.update(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): return self.req_e, 'notFound' @executor.mock_valid_lfid() @executor.update(httplib.FORBIDDEN, message.exist_base) def test_newNameExist(self): return self.req_e, self.req_d.name @executor.mock_valid_lfid() @executor.update(httplib.FORBIDDEN, message.no_update()) def test_noUpdate(self): 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') return req, self.req_d.name def _assert_update(self, req, body): self.assertEqual(self.index_d, body._id) self.assert_body(body, req) _, new_body = self.get(req.name) self.assertEqual(self.index_d, new_body._id) self.assert_body(new_body, req)
def wrapper(self, *args, **kwargs): if self.table in ['pods']: testapi_id = self.get_secure_cookie(constants.TESTAPI_ID) if not testapi_id: raises.Unauthorized(message.not_login()) user_info = yield dbapi.db_find_one('users', {'user': testapi_id}) if not user_info: raises.Unauthorized(message.not_lfid()) kwargs['owner'] = testapi_id ret = yield gen.coroutine(method)(self, *args, **kwargs) raise gen.Return(ret)
class TestPodCreate(TestPodBase): @executor.create(httplib.BAD_REQUEST, message.not_login()) def test_notlogin(self): return self.req_d @executor.mock_invalid_lfid() @executor.create(httplib.BAD_REQUEST, message.not_lfid()) def test_invalidLfid(self): return self.req_d @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.no_body()) def test_withoutBody(self): return None @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_emptyName(self): return pod_models.PodCreateRequest('') @executor.mock_valid_lfid() @executor.create(httplib.BAD_REQUEST, message.missing('name')) def test_noneName(self): return pod_models.PodCreateRequest(None) @executor.mock_valid_lfid() @executor.create(httplib.OK, 'assert_create_body') def test_success(self): return self.req_d @executor.mock_valid_lfid() @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExist(self): fake_pymongo.pods.insert(self.pod_d.format()) return self.req_d @executor.mock_valid_lfid() @executor.create(httplib.FORBIDDEN, message.exist_base) def test_alreadyExistCaseInsensitive(self): fake_pymongo.pods.insert(self.pod_d.format()) self.req_d.name = self.req_d.name.upper() return self.req_d
class TestProjectDelete(TestProjectBase): @executor.mock_valid_lfid() def setUp(self): super(TestProjectDelete, self).setUp() self.create_d() @executor.delete(httplib.BAD_REQUEST, message.not_login()) def test_notlogin(self): return self.req_d.name @executor.delete(httplib.NOT_FOUND, message.not_found_base) def test_notFound(self): return 'notFound' @executor.mock_valid_lfid() @executor.delete(httplib.OK, '_assert_delete') def test_success(self): return self.req_d.name def _assert_delete(self, body): self.assertEqual(body, '') code, body = self.get(self.req_d.name) self.assertEqual(code, httplib.NOT_FOUND)