BaseApiTest class for conductor api module 61/31161/1
authorDileep Ranganathan <dileep.ranganathan@intel.com>
Fri, 9 Feb 2018 19:04:24 +0000 (11:04 -0800)
committerDileep Ranganathan <dileep.ranganathan@intel.com>
Sat, 10 Feb 2018 18:08:29 +0000 (10:08 -0800)
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>
conductor/conductor/tests/unit/api/__init__.py [new file with mode: 0644]
conductor/conductor/tests/unit/api/base_api.py [new file with mode: 0644]

diff --git a/conductor/conductor/tests/unit/api/__init__.py b/conductor/conductor/tests/unit/api/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/conductor/conductor/tests/unit/api/base_api.py b/conductor/conductor/tests/unit/api/base_api.py
new file mode 100644 (file)
index 0000000..f3f6747
--- /dev/null
@@ -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