[Kimchi-devel] [PATCH V3 29/34] Adapt automated tests to the new plugin structure

Lucio Correia luciojhc at linux.vnet.ibm.com
Wed Jul 8 19:18:01 UTC 2015


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
Signed-off-by: Gustavo Y. Ribeiro <gyr at linux.vnet.ibm.com>
---
 plugins/kimchi/tests/test_config.py.in |  119 +++++++++++++++----------------
 plugins/kimchi/tests/test_exception.py |    4 +-
 plugins/kimchi/tests/test_rest.py      |    1 -
 plugins/kimchi/tests/utils.py          |    4 +-
 4 files changed, 62 insertions(+), 66 deletions(-)

diff --git a/plugins/kimchi/tests/test_config.py.in b/plugins/kimchi/tests/test_config.py.in
index 337218e..19ae0ba 100644
--- a/plugins/kimchi/tests/test_config.py.in
+++ b/plugins/kimchi/tests/test_config.py.in
@@ -18,9 +18,14 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 import unittest
+from cherrypy.lib.reprconf import Parser
+
+from wok.config import Paths
+
+from wok.plugins.kimchi.config import get_debugreports_path
+from wok.plugins.kimchi.config import get_screenshot_path
+from wok.plugins.kimchi.config import KimchiPaths
 
-from wok import config
-from wok.config import Paths, PluginPaths, KimchiConfig
 
 get_prefix = None
 
@@ -31,7 +36,7 @@ def setUpModule():
 
 
 def tearDownModule():
-    Paths.get_prefix = PluginPaths.get_prefix = get_prefix
+    Paths.get_prefix = KimchiPaths.get_prefix = get_prefix
 
 
 class ConfigTests(unittest.TestCase):
@@ -43,52 +48,50 @@ class ConfigTests(unittest.TestCase):
         self.assertEquals(actual, expected)
 
     def test_installed_paths(self):
-        Paths.get_prefix = lambda self: '@pkgdatadir@'
+        Paths.get_prefix = lambda self: '@datadir@/wok'
         paths = Paths()
-        self.assertInstalledPath(paths.state_dir, '/var/lib/kimchi')
-        self.assertInstalledPath(paths.log_dir, '/var/log/kimchi')
-        self.assertInstalledPath(paths.conf_dir, '/etc/kimchi')
-        self.assertInstalledPath(paths.src_dir, '@kimchidir@')
-        self.assertInstalledPath(paths.plugins_dir, '@kimchidir@/plugins')
-        self.assertInstalledPath(paths.ui_dir, '@pkgdatadir@/ui')
+        self.assertInstalledPath(paths.state_dir, '/var/lib/wok')
+        self.assertInstalledPath(paths.log_dir, '/var/log/wok')
+        self.assertInstalledPath(paths.conf_dir, '/etc/wok')
+        self.assertInstalledPath(paths.src_dir, '@wokdir@')
+        self.assertInstalledPath(paths.plugins_dir, '@wokdir@/plugins')
+        self.assertInstalledPath(paths.ui_dir, '@datadir@/wok/ui')
         self.assertInstalledPath(paths.mo_dir, '@prefix@/share/locale')
 
     def test_uninstalled_paths(self):
-        Paths.get_prefix = lambda self: '/home/user/kimchi'
+        Paths.get_prefix = lambda self: '/home/user/wok'
         paths = Paths()
-        self.assertEquals(paths.state_dir, '/home/user/kimchi/data')
-        self.assertEquals(paths.log_dir, '/home/user/kimchi/log')
-        self.assertEquals(paths.conf_dir, '/home/user/kimchi/src')
-        self.assertEquals(paths.src_dir, '/home/user/kimchi/src/kimchi')
-        self.assertEquals(paths.plugins_dir, '/home/user/kimchi/plugins')
-        self.assertEquals(paths.ui_dir, '/home/user/kimchi/ui')
-        self.assertEquals(paths.mo_dir, '/home/user/kimchi/mo')
+        self.assertEquals(paths.state_dir, '/home/user/wok/data')
+        self.assertEquals(paths.log_dir, '/home/user/wok/log')
+        self.assertEquals(paths.conf_dir, '/home/user/wok/src')
+        self.assertEquals(paths.src_dir, '/home/user/wok/src/wok')
+        self.assertEquals(paths.plugins_dir, '/home/user/wok/plugins')
+        self.assertEquals(paths.ui_dir, '/home/user/wok/ui')
+        self.assertEquals(paths.mo_dir, '/home/user/wok/mo')
 
     def test_installed_plugin_paths(self):
-        PluginPaths.get_prefix = lambda self: '@pkgdatadir@'
-        paths = PluginPaths('sample')
-        self.assertInstalledPath(paths.conf_dir, '/etc/kimchi/plugins.d')
+        KimchiPaths.get_prefix = lambda self: '@datadir@/wok'
+        paths = KimchiPaths()
+        self.assertInstalledPath(paths.conf_dir, '/etc/wok/plugins.d')
         self.assertInstalledPath(paths.conf_file,
-                                 '/etc/kimchi/plugins.d/sample.conf')
-        self.assertInstalledPath(paths.src_dir, '@kimchidir@/plugins/sample')
+                                 '/etc/wok/plugins.d/kimchi.conf')
+        self.assertInstalledPath(paths.src_dir, '@wokdir@/plugins/kimchi')
         self.assertInstalledPath(paths.ui_dir,
-                                 '@pkgdatadir@/plugins/sample/ui')
-        self.assertInstalledPath(paths.mo_dir,
-                                 '@pkgdatadir@/plugins/sample/mo')
+                                 '@datadir@/wok/plugins/kimchi/ui')
+        self.assertInstalledPath(paths.mo_dir, '@prefix@/share/locale')
 
     def test_uninstalled_plugin_paths(self):
-        PluginPaths.get_prefix = lambda self: '/home/user/kimchi'
-        paths = PluginPaths('sample')
-        self.assertEquals(paths.conf_dir, '/home/user/kimchi/plugins/sample')
+        KimchiPaths.get_prefix = lambda self: '/home/user/wok'
+        paths = KimchiPaths()
+        self.assertEquals(paths.conf_dir, '/home/user/wok/plugins/kimchi')
         self.assertEquals(
-            paths.conf_file, '/home/user/kimchi/plugins/sample/sample.conf')
-        self.assertEquals(paths.src_dir, '/home/user/kimchi/plugins/sample')
-        self.assertEquals(paths.ui_dir, '/home/user/kimchi/plugins/sample/ui')
-        self.assertEquals(paths.mo_dir, '/home/user/kimchi/plugins/sample/mo')
+            paths.conf_file, '/home/user/wok/plugins/kimchi/kimchi.conf')
+        self.assertEquals(paths.src_dir, '/home/user/wok/plugins/kimchi')
+        self.assertEquals(paths.ui_dir, '/home/user/wok/plugins/kimchi/ui')
+        self.assertEquals(paths.mo_dir, '/home/user/wok/plugins/kimchi/mo')
 
     def test_kimchi_config(self):
-        Paths.get_prefix = PluginPaths.get_prefix = get_prefix
-        paths = Paths()
+        Paths.get_prefix = KimchiPaths.get_prefix = get_prefix
         CACHEEXPIRES = 31536000
         SESSIONSTIMEOUT = 10
         configObj = {
@@ -98,99 +101,93 @@ class ConfigTests(unittest.TestCase):
                 'tools.nocache.on': True,
                 'tools.proxy.on': True,
                 'tools.sessions.on': True,
-                'tools.sessions.name': 'kimchi',
+                'tools.sessions.name': 'wok',
                 'tools.sessions.secure': True,
                 'tools.sessions.httponly': True,
                 'tools.sessions.locking': 'explicit',
                 'tools.sessions.storage_type': 'ram',
                 'tools.sessions.timeout': SESSIONSTIMEOUT,
-                'tools.kimchiauth.on': False
+                'tools.wokauth.on': False
             },
             '/novnc': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': paths.novnc_dir,
+                'tools.staticdir.dir': KimchiPaths().novnc_dir,
                 'tools.nocache.on': True,
-                'tools.kimchiauth.on': True
+                'tools.wokauth.on': True
             },
             '/spice_auto.html': {
                 'tools.staticfile.on': True,
-                'tools.staticfile.filename': paths.spice_file,
+                'tools.staticfile.filename': KimchiPaths().spice_file,
                 'tools.nocache.on': True,
-                'tools.kimchiauth.on': True
+                'tools.wokauth.on': True
             },
             '/spice-html5': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': paths.spice_dir,
+                'tools.staticdir.dir': KimchiPaths().spice_dir,
                 'tools.nocache.on': True
             },
             '/spice-html5/spice.css': {
                 'tools.staticfile.on': True,
-                'tools.staticfile.filename': paths.spice_css_file,
+                'tools.staticfile.filename': KimchiPaths().spice_css_file,
                 'tools.nocache.on': True,
             },
             '/kimchi-ui.html': {
-                'tools.kimchiauth.on': True
+                'tools.wokauth.on': True
             },
             '/css': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': '%s/ui/css' % paths.prefix,
+                'tools.staticdir.dir': '%s/ui/css' % KimchiPaths().prefix,
                 'tools.expires.on': True,
                 'tools.expires.secs': CACHEEXPIRES,
                 'tools.nocache.on': False
             },
             '/js': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': '%s/ui/js' % paths.prefix,
+                'tools.staticdir.dir': '%s/ui/js' % KimchiPaths().prefix,
                 'tools.expires.on': True,
                 'tools.expires.secs': CACHEEXPIRES,
                 'tools.nocache.on': False
             },
             '/libs': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': '%s/ui/libs' % paths.prefix,
+                'tools.staticdir.dir': '%s/ui/libs' % KimchiPaths().prefix,
                 'tools.expires.on': True,
                 'tools.expires.secs': CACHEEXPIRES,
                 'tools.nocache.on': False,
             },
             '/images': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': '%s/ui/images' % paths.prefix,
+                'tools.staticdir.dir': '%s/ui/images' % KimchiPaths().prefix,
                 'tools.nocache.on': False
             },
             '/data/screenshots': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': config.get_screenshot_path(),
+                'tools.staticdir.dir': get_screenshot_path(),
                 'tools.nocache.on': False
             },
             '/data/debugreports': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': config.get_debugreports_path(),
+                'tools.staticdir.dir': get_debugreports_path(),
                 'tools.nocache.on': False,
-                'tools.kimchiauth.on': True,
+                'tools.wokauth.on': True,
                 'tools.staticdir.content_types': {'xz': 'application/x-xz'}
             },
-            '/config/ui/tabs.xml': {
-                'tools.staticfile.on': True,
-                'tools.staticfile.filename': '%s/config/ui/tabs.xml' %
-                                             paths.prefix,
-                'tools.nocache.on': True
-            },
             '/favicon.ico': {
                 'tools.staticfile.on': True,
                 'tools.staticfile.filename':
-                '%s/images/logo.ico' % paths.ui_dir
+                '%s/images/logo.ico' % KimchiPaths().ui_dir
             },
             '/robots.txt': {
                 'tools.staticfile.on': True,
-                'tools.staticfile.filename': '%s/robots.txt' % paths.ui_dir
+                'tools.staticfile.filename': '%s/robots.txt' % KimchiPaths().ui_dir
             },
             '/help': {
                 'tools.staticdir.on': True,
-                'tools.staticdir.dir': '%s/ui/pages/help' % paths.prefix,
+                'tools.staticdir.dir': '%s/ui/pages/help' % KimchiPaths().prefix,
                 'tools.staticdir.index': 'en_US/index.html',
                 'tools.nocache.on': True
             }
         }
 
-        kimchi_config = KimchiConfig()
+        kimchi_config = Parser().dict_from_file(KimchiPaths().conf_file)
         self.assertEquals(kimchi_config, configObj)
diff --git a/plugins/kimchi/tests/test_exception.py b/plugins/kimchi/tests/test_exception.py
index 32b6baf..c0dadab 100644
--- a/plugins/kimchi/tests/test_exception.py
+++ b/plugins/kimchi/tests/test_exception.py
@@ -62,7 +62,7 @@ class ExceptionTests(unittest.TestCase):
 
         # test 405 wrong method
         resp = json.loads(request(host, ssl_port, '/', None, 'DELETE').read())
-        msg = u'KCHAPI0002E: Delete is not allowed for kimchiroot'
+        msg = u'KCHAPI0002E: Delete is not allowed for wokroot'
         self.assertEquals('405 Method Not Allowed', resp.get('code'))
         self.assertEquals(msg, resp.get('reason'))
 
@@ -92,7 +92,7 @@ class ExceptionTests(unittest.TestCase):
 
         # test 405 wrong method
         resp = json.loads(request(host, ssl_port, '/', None, 'DELETE').read())
-        msg = u'KCHAPI0002E: Delete is not allowed for kimchiroot'
+        msg = u'KCHAPI0002E: Delete is not allowed for wokroot'
         self.assertEquals('405 Method Not Allowed', resp.get('code'))
         self.assertEquals(msg, resp.get('reason'))
 
diff --git a/plugins/kimchi/tests/test_rest.py b/plugins/kimchi/tests/test_rest.py
index 69db7a7..52e3404 100644
--- a/plugins/kimchi/tests/test_rest.py
+++ b/plugins/kimchi/tests/test_rest.py
@@ -30,7 +30,6 @@ from functools import partial
 
 import iso_gen
 from wok.plugins.kimchi import mockmodel
-import wok.server
 from wok.plugins.kimchi.osinfo import get_template_default
 from wok.rollbackcontext import RollbackContext
 from wok.utils import add_task
diff --git a/plugins/kimchi/tests/utils.py b/plugins/kimchi/tests/utils.py
index e22bffa..dceed9c 100644
--- a/plugins/kimchi/tests/utils.py
+++ b/plugins/kimchi/tests/utils.py
@@ -38,7 +38,7 @@ from lxml import etree
 
 from wok.plugins.kimchi import mockmodel
 import wok.server
-from wok.config import config, paths
+from wok.config import config, PluginPaths
 from wok.auth import User, USER_NAME, USER_GROUPS, USER_ROLES, tabs
 from wok.exception import NotFoundError, OperationFailed
 from wok.utils import wok_log
@@ -167,7 +167,7 @@ def get_remote_iso_path():
     """
     host_arch = os.uname()[4]
     remote_path = ''
-    with open(os.path.join(paths.conf_dir, 'distros.d', 'fedora.json')) \
+    with open(os.path.join(PluginPaths('kimchi').conf_dir, 'distros.d', 'fedora.json')) \
             as fedora_isos:
         # Get a list of dicts
         json_isos_list = json.load(fedora_isos)
-- 
1.7.1




More information about the Kimchi-devel mailing list