From 0428e150be3c2090655b4d12d08afc6d5b1f4ecf Mon Sep 17 00:00:00 2001 From: Romain Ziba Date: Thu, 28 May 2015 10:34:20 +0200 Subject: [PATCH] Add functional tests Use pbr post versioning Change-Id: Iad68c1b75318654b89e1b68bf593031470a0522c --- cerberus/tests/__init__.py | 15 --- cerberus/tests/functional/__init__.py | 0 cerberus/tests/functional/api/__init__.py | 0 cerberus/tests/functional/api/v1/__init__.py | 0 cerberus/tests/functional/api/v1/test_api.py | 53 ++++++++ cerberus/tests/functional/base.py | 121 +++++++++++++++++++ functionaltests/README.rst | 15 +++ setup.cfg | 1 - 8 files changed, 189 insertions(+), 16 deletions(-) delete mode 100644 cerberus/tests/__init__.py create mode 100644 cerberus/tests/functional/__init__.py create mode 100644 cerberus/tests/functional/api/__init__.py create mode 100644 cerberus/tests/functional/api/v1/__init__.py create mode 100644 cerberus/tests/functional/api/v1/test_api.py create mode 100644 cerberus/tests/functional/base.py create mode 100644 functionaltests/README.rst diff --git a/cerberus/tests/__init__.py b/cerberus/tests/__init__.py deleted file mode 100644 index 73ca62b..0000000 --- a/cerberus/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -# Copyright (c) 2014 EUROGICIEL -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/cerberus/tests/functional/__init__.py b/cerberus/tests/functional/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cerberus/tests/functional/api/__init__.py b/cerberus/tests/functional/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cerberus/tests/functional/api/v1/__init__.py b/cerberus/tests/functional/api/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cerberus/tests/functional/api/v1/test_api.py b/cerberus/tests/functional/api/v1/test_api.py new file mode 100644 index 0000000..43af4f0 --- /dev/null +++ b/cerberus/tests/functional/api/v1/test_api.py @@ -0,0 +1,53 @@ +# +# Copyright (c) 2015 EUROGICIEL +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from cerberus.tests.functional import base + + +class AlarmTestsV1(base.TestCase): + + _service = 'security' + + def test_list_alarms(self): + resp, body = self.client.get("v1/security_alarms") + self.assertEqual(200, resp.status) + + +class ReportTestsV1(base.TestCase): + + _service = 'security' + + def test_list_reports(self): + resp, body = self.client.get("v1/security_reports") + self.assertEqual(200, resp.status) + + +class TaskTestsV1(base.TestCase): + + _service = 'security' + + def test_list_tasks(self): + resp, body = self.client.get("v1/tasks") + self.assertEqual(200, resp.status) + + +class PluginTestsV1(base.TestCase): + + _service = 'security' + + def test_list_plugins(self): + resp, body = self.client.get("v1/plugins") + self.assertEqual(200, resp.status) diff --git a/cerberus/tests/functional/base.py b/cerberus/tests/functional/base.py new file mode 100644 index 0000000..763825a --- /dev/null +++ b/cerberus/tests/functional/base.py @@ -0,0 +1,121 @@ +# +# Copyright (c) 2015 EUROGICIEL +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import mock +import os + +from tempest import clients +from tempest import config +from tempest_lib import auth +from tempest_lib import base +from tempest_lib.common import rest_client +from tempest_lib import exceptions + + +CONF = config.CONF + + +def get_resource(path): + main_package = 'cerberus/tests' + dir_path = __file__[0:__file__.find(main_package) + len(main_package) + 1] + + return open(dir_path + 'resources/' + path).read() + + +def find_items(items, **props): + def _matches(item, **props): + for prop_name, prop_val in props.iteritems(): + if item[prop_name] != prop_val: + return False + + return True + + filtered = filter(lambda item: _matches(item, **props), items) + + if len(filtered) == 1: + return filtered[0] + + return filtered + + +class CerberusClientBase(rest_client.RestClient): + + def __init__(self, auth_provider, service_type): + super(CerberusClientBase, self).__init__( + auth_provider=auth_provider, + service=service_type, + region=CONF.identity.region) + + if service_type not in ('security'): + msg = ("Invalid parameter 'service_type'. ") + raise exceptions.UnprocessableEntity(msg) + + self.endpoint_url = 'publicURL' + + self.workbooks = [] + self.executions = [] + self.workflows = [] + self.triggers = [] + self.actions = [] + + +class CerberusClientV1(CerberusClientBase): + + def list(self): + self.get("http://127.0.0.1:8300/v1") + + +class AuthProv(auth.KeystoneV2AuthProvider): + + def __init__(self): + self.alt_part = None + + def auth_request(self, method, url, *args, **kwargs): + req_url, headers, body = super(AuthProv, self).auth_request( + method, url, *args, **kwargs) + return 'http://localhost:8300/{0}/{1}'.format( + 'v1', url), headers, body + + def get_auth(self): + return 'mock_str', 'mock_str' + + def base_url(self, *args, **kwargs): + return '' + + +class TestCase(base.BaseTestCase): + + @classmethod + def setUpClass(cls): + """This method allows to initialize authentication before + each test case and define parameters of Mistral API Service. + """ + super(TestCase, cls).setUpClass() + + if 'WITHOUT_AUTH' in os.environ: + cls.mgr = mock.MagicMock() + cls.mgr.auth_provider = AuthProv() + else: + cls.mgr = clients.Manager() + + cls.client = CerberusClientV1( + cls.mgr.auth_provider, cls._service) + + def setUp(self): + super(TestCase, self).setUp() + + def tearDown(self): + super(TestCase, self).tearDown() diff --git a/functionaltests/README.rst b/functionaltests/README.rst new file mode 100644 index 0000000..c047afe --- /dev/null +++ b/functionaltests/README.rst @@ -0,0 +1,15 @@ +FUNCTIONAL TEST +=============== + +Prerequisites +------------- + +1. **tempest** +2. **tempest_lib** +3. **nose** +4. **Configure tempest** + + +USAGE +----- +nosetests -sv cerberus/tests/functional/ \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 1bb3880..d4f094d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,6 @@ [metadata] name = cerberus summary = Cerberus security component -version = 1.2-1 description-file = README.rst author = OpenStack