diff options
author | Dileep Ranganathan <dileep.ranganathan@intel.com> | 2018-02-10 12:00:18 -0800 |
---|---|---|
committer | Dileep Ranganathan <dileep.ranganathan@intel.com> | 2018-02-11 23:26:26 +0000 |
commit | 1c260cbd69b7e0e34c01dae57c19ce713bbf3277 (patch) | |
tree | 63330e5e103585eb2646b6663830949aea6c2552 /conductor | |
parent | f55f488b69b97ab4bfba039b01aad97563e7c065 (diff) |
Unit test for RootController and V1Controller
Addedd unit tests for RootController and V1Controller
Updated tox.ini to support coverage
Change-Id: I3adf9d2268776382ff1f067857947af9718c9ac8
Issue-ID: OPTFRA-68
Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
Diffstat (limited to 'conductor')
7 files changed, 111 insertions, 3 deletions
diff --git a/conductor/conductor/tests/unit/api/base_api.py b/conductor/conductor/tests/unit/api/base_api.py index f3f6747..ac89a57 100644 --- a/conductor/conductor/tests/unit/api/base_api.py +++ b/conductor/conductor/tests/unit/api/base_api.py @@ -24,8 +24,11 @@ import pecan import pecan.testing from oslo_config import cfg from oslo_config import fixture as config_fixture +from oslo_serialization import jsonutils from oslotest import base as oslo_test_base +from conductor import service + class BaseApiTest(oslo_test_base.BaseTestCase): """Pecan controller functional testing class. @@ -78,4 +81,9 @@ class BaseApiTest(oslo_test_base.BaseTestCase): def _set_config(self): self.cfg_fixture = self.useFixture(config_fixture.Config(cfg.CONF)) self.cfg_fixture.config(keyspace='conductor_rpc', - group='messaging_server')
\ No newline at end of file + group='messaging_server') + + def assertJsonEqual(self, expected, observed): + """Asserts that 2 complex data structures are json equivalent.""" + self.assertEqual(jsonutils.dumps(expected, sort_keys=True), + jsonutils.dumps(observed, sort_keys=True))
\ No newline at end of file diff --git a/conductor/conductor/tests/unit/api/controller/__init__.py b/conductor/conductor/tests/unit/api/controller/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/__init__.py diff --git a/conductor/conductor/tests/unit/api/controller/test_root.py b/conductor/conductor/tests/unit/api/controller/test_root.py new file mode 100644 index 0000000..3dbb66c --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/test_root.py @@ -0,0 +1,35 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# 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. +# +# ------------------------------------------------------------------------- +# +"""Test case for RootController /""" + +import json + +from conductor.tests.unit.api import base_api + + +class TestRoot(base_api.BaseApiTest): + + def test_get_index(self): + actual_response = self.app.get('/') + req_json_file = './conductor/tests/unit/api/controller/versions.json' + expected_response = json.loads(open(req_json_file).read()) + print('GOT:%s' % actual_response) + self.assertJsonEqual(actual_response.status_int, 200) + self.assertJsonEqual(expected_response, + json.loads(actual_response.body)) diff --git a/conductor/conductor/tests/unit/api/controller/v1/__init__.py b/conductor/conductor/tests/unit/api/controller/v1/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/v1/__init__.py diff --git a/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py b/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py new file mode 100644 index 0000000..ade3f2c --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/v1/test_v1_root.py @@ -0,0 +1,29 @@ +# +# ------------------------------------------------------------------------- +# Copyright (c) 2018 Intel Corporation Intellectual Property +# +# 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. +# +# ------------------------------------------------------------------------- +# +"""Test case for V1Controller /""" + +from conductor.tests.unit.api import base_api + + +class TestV1Root(base_api.BaseApiTest): + + def test_get_v1_root(self): + actual_response = self.app.get('/v1', expect_errors=True) + print('GOT:%s' % actual_response) + self.assertEqual(actual_response.status_int, 405) diff --git a/conductor/conductor/tests/unit/api/controller/versions.json b/conductor/conductor/tests/unit/api/controller/versions.json new file mode 100644 index 0000000..885ce01 --- /dev/null +++ b/conductor/conductor/tests/unit/api/controller/versions.json @@ -0,0 +1,26 @@ +{ + "versions": [ + { + "id": "v1", + "media-types": [ + { + "type": "application/vnd.onap.has-v1+json", + "base": "application/json" + } + ], + "updated": "2016-11-01T00:00:00Z", + "links": [ + { + "rel": "self", + "href": "http://localhost/v1" + }, + { + "type": "text/html", + "rel": "describedby", + "href": "https://wiki.onap.org/pages/viewpage.action?pageId=16005528" + } + ], + "status": "EXPERIMENTAL" + } + ] +}
\ No newline at end of file diff --git a/conductor/tox.ini b/conductor/tox.ini index 498770f..99af8b8 100644 --- a/conductor/tox.ini +++ b/conductor/tox.ini @@ -15,6 +15,7 @@ commands = {toxinidir}/tools/pretty_tox.sh "{posargs}" oslo-config-generator --config-file=etc/conductor/conductor-config-generator.conf whitelist_externals = bash + find [testenv:functional] setenv = VIRTUAL_ENV={envdir} @@ -24,9 +25,18 @@ commands = bash -x {toxinidir}/run-functional-tests.sh "{posargs}" [testenv:cover] -setenv = OS_TEST_PATH=conductor/tests +setenv = VIRTUAL_ENV={envdir} + LANGUAGE=en_US + OS_TEST_PATH=conductor/tests/unit + PYTHON=coverage run --source conductor --omit='*tests*' --parallel-mode commands = - python setup.py testr --slowest --coverage --testr-args='^(?!conductor_integrationtests){posargs}' + coverage erase + find . -type f -name "*.pyc" -delete + {toxinidir}/tools/pretty_tox.sh "{posargs}" + coverage combine + coverage html -d cover + coverage xml -o cover/coverage.xml + coverage report [testenv:pep8] deps = hacking<0.12,>=0.11.0 |