summaryrefslogtreecommitdiffstats
path: root/conductor
diff options
context:
space:
mode:
authorDileep Ranganathan <dileep.ranganathan@intel.com>2018-02-09 11:04:24 -0800
committerDileep Ranganathan <dileep.ranganathan@intel.com>2018-02-10 10:08:29 -0800
commitf55f488b69b97ab4bfba039b01aad97563e7c065 (patch)
treec18b79c1c75136388eded598814f5d8ddc06d25f /conductor
parent4f58c4461a09adbaff082b0ef3f48688cc59bfd1 (diff)
BaseApiTest class for conductor api module
BaseTest class for all tests in conductor api module Uses pecan.testing, Mock MUSIC API Change-Id: I720a4aa7edd4a975ef7ec50bb6647b5825129a67 Issue-ID: OPTFRA-81 Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
Diffstat (limited to 'conductor')
-rw-r--r--conductor/conductor/tests/unit/api/__init__.py0
-rw-r--r--conductor/conductor/tests/unit/api/base_api.py81
2 files changed, 81 insertions, 0 deletions
diff --git a/conductor/conductor/tests/unit/api/__init__.py b/conductor/conductor/tests/unit/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/conductor/conductor/tests/unit/api/__init__.py
diff --git a/conductor/conductor/tests/unit/api/base_api.py b/conductor/conductor/tests/unit/api/base_api.py
new file mode 100644
index 0000000..f3f6747
--- /dev/null
+++ b/conductor/conductor/tests/unit/api/base_api.py
@@ -0,0 +1,81 @@
+#
+# -------------------------------------------------------------------------
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+"""Base classes for conductor/api tests."""
+
+import os
+
+import pecan
+import pecan.testing
+from oslo_config import cfg
+from oslo_config import fixture as config_fixture
+from oslotest import base as oslo_test_base
+
+
+class BaseApiTest(oslo_test_base.BaseTestCase):
+ """Pecan controller functional testing class.
+
+ Used for functional tests of Pecan controllers where you need to
+ test your literal application and its integration with the
+ framework.
+ """
+
+ def setUp(self):
+ super(BaseApiTest, self).setUp()
+ # self._set_config()
+ # TODO(dileep.ranganathan): Move common mock and configs to BaseTest
+ cfg.CONF.set_override('mock', True, 'music_api')
+ self.app = self._make_app()
+
+ def reset_pecan():
+ pecan.set_config({}, overwrite=True)
+
+ self.addCleanup(reset_pecan)
+
+ def _make_app(self):
+ # Determine where we are so we can set up paths in the config
+ root_dir = self.path_get()
+
+ self.app_config = {
+ 'app': {
+ 'root': 'conductor.api.controllers.root.RootController',
+ 'modules': ['conductor.api'],
+ },
+ }
+ return pecan.testing.load_test_app(self.app_config, conf=cfg.CONF)
+
+ def path_get(self, project_file=None):
+ """Get the absolute path to a file. Used for testing the API.
+
+ :param project_file: File whose path to return. Default: None.
+ :returns: path to the specified file, or path to project root.
+ """
+ root = os.path.abspath(os.path.join(os.path.dirname(__file__),
+ '..',
+ '..',
+ )
+ )
+ if project_file:
+ return os.path.join(root, project_file)
+ else:
+ return root
+
+ 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