
Tested-By: Paulo Vital <pvital@linux.vnet.ibm.com> Reviewed-By: Paulo Vital <pvital@linux.vnet.ibm.com> On Tue, 2015-10-13 at 21:37 -0300, Aline Manera wrote:
Some tests in plugin/kimchi/tests/test_config.py.in were related to Wok configuration, so move those tests to Wok.
Also improve test_config.py.in on Wok to also verify the UI configuration.
And fix some test cases on Kimchi related test_config.py.in
Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- src/wok/config.py.in | 31 ++-- src/wok/plugins/kimchi/tests/test_config.py.in | 206 +++++++-------- ---------- tests/test_config.py.in | 115 +++++++++++++- 3 files changed, 182 insertions(+), 170 deletions(-)
diff --git a/src/wok/config.py.in b/src/wok/config.py.in index b33fb6b..b17d1ed 100644 --- a/src/wok/config.py.in +++ b/src/wok/config.py.in @@ -55,6 +55,8 @@ FONTS_PATH = { ] }
+SESSIONSTIMEOUT = 10 # session time out is 10 minutes +
def get_object_store(): return os.path.join(paths.state_dir, 'objectstore') @@ -88,6 +90,13 @@ class Paths(object): self.plugins_dir = self.add_prefix('src/wok/plugins') self.mo_dir = self.add_prefix('mo')
+ for font in FONT_FILES.keys(): + paths = FONTS_PATH[font] + for path in paths: + font_file = os.path.join(path, FONT_FILES[font][0]) + if os.path.exists(font_file): + setattr(self, '%s_dir' % font, path) + def get_prefix(self): if __file__.startswith("/"): base = os.path.dirname(__file__) @@ -147,24 +156,20 @@ class UIConfig(dict): 'tools.expires.secs': CACHEEXPIRES})
for font, files in FONT_FILES.iteritems(): - paths = FONTS_PATH[font] - for path in paths: - for filename in files: - font_file = os.path.join(path, filename) - if os.path.exists(font_file): - ui_configs['/fonts/%s' % filename] = { - 'tools.staticfile.on': True, - 'tools.staticfile.filename': font_file, - 'tools.wokauth.on': False, - 'tools.nocache.on': False} + font_dir = getattr(paths, "%s_dir" % font) + for filename in files: + font_file = os.path.join(font_dir, filename) + if os.path.exists(font_file): + ui_configs['/fonts/%s' % filename] = { + 'tools.staticfile.on': True, + 'tools.staticfile.filename': font_file, + 'tools.wokauth.on': False, + 'tools.nocache.on': False}
self.update(ui_configs)
class WokConfig(dict): - # session time out is 10 minutes - SESSIONSTIMEOUT = 10 - wok_config = { '/': { 'tools.trailing_slash.on': False, diff --git a/src/wok/plugins/kimchi/tests/test_config.py.in b/src/wok/plugins/kimchi/tests/test_config.py.in index e4db15a..fb23b5c 100644 --- a/src/wok/plugins/kimchi/tests/test_config.py.in +++ b/src/wok/plugins/kimchi/tests/test_config.py.in @@ -20,7 +20,8 @@ import unittest from cherrypy.lib.reprconf import Parser
-from wok.config import Paths, PluginPaths, WokConfig +from wok.config import CACHEEXPIRES, SESSIONSTIMEOUT +from wok.config import Paths, PluginPaths
from wok.plugins.kimchi.config import get_debugreports_path from wok.plugins.kimchi.config import get_screenshot_path @@ -47,28 +48,6 @@ class ConfigTests(unittest.TestCase): expected = usr_local + expected self.assertEquals(actual, expected)
- def test_installed_paths(self): - Paths.get_prefix = lambda self: '@datadir@/wok' - paths = Paths() - 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@/plugin s') - self.assertInstalledPath(paths.ui_dir, '@datadir@/wok/ui') - self.assertInstalledPath(paths.mo_dir, '@prefix@/share/local e') - - def test_uninstalled_paths(self): - Paths.get_prefix = lambda self: '/home/user/wok' - paths = Paths() - 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): KimchiPaths.get_prefix = lambda self: '@datadir@/wok' paths = KimchiPaths() @@ -81,100 +60,27 @@ class ConfigTests(unittest.TestCase): self.assertInstalledPath(paths.mo_dir, '@prefix@/share/local e')
def test_uninstalled_plugin_paths(self): - 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/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_wok_config(self): - Paths.get_prefix = PluginPaths.get_prefix = get_prefix - paths = Paths() - CACHEEXPIRES = 31536000 - SESSIONSTIMEOUT = 10 - configObj = { - '/': { - 'tools.trailing_slash.on': False, - 'request.methods_with_bodies': ('POST', 'PUT'), - 'tools.nocache.on': True, - 'tools.proxy.on': True, - 'tools.sessions.on': True, - '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.wokauth.on': False - }, - '/base64/jquery.base64.js': { - 'tools.staticfile.on': True, - 'tools.staticfile.filename': '%s/base64/jquery.base64.js' % - paths.ui_dir, - 'tools.nocache.on': True, - }, - '/wok-ui.html': { - 'tools.wokauth.on': True - }, - '/css': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/css' % paths.prefix, - 'tools.expires.on': True, - 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False - }, - '/js': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/js' % paths.prefix, - 'tools.expires.on': True, - 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False - }, - '/libs': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/libs' % paths.prefix, - 'tools.expires.on': True, - 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False - }, - '/images': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/images' % paths.prefix, - 'tools.nocache.on': False, - 'tools.wokauth.on': False - }, - '/favicon.ico': { - 'tools.staticfile.on': True, - 'tools.staticfile.filename': - '%s/images/logo.ico' % paths.ui_dir - }, - '/robots.txt': { - 'tools.staticfile.on': True, - 'tools.staticfile.filename': '%s/robots.txt' % paths.ui_dir - }, - } - - wok_config = WokConfig() - self.assertEquals(wok_config, configObj) + prefix = paths.prefix + self.assertEquals(paths.conf_dir, '%s/src/wok/plugins/kimchi' % prefix) + self.assertEquals(paths.conf_file, + '%s/src/wok/plugins/kimchi/kimchi.conf' % prefix) + self.assertEquals(paths.src_dir, '%s/src/wok/plugins/kimchi' % prefix) + self.assertEquals(paths.ui_dir, + '%s/src/wok/plugins/kimchi/ui' % prefix) + self.assertEquals(paths.mo_dir, + '%s/src/wok/plugins/kimchi/mo' % prefix)
def test_kimchi_config(self): KimchiPaths.get_prefix = PluginPaths.get_prefix = get_prefix paths = KimchiPaths() pluginPrefix = paths.add_prefix(paths.plugin_dir) - CACHEEXPIRES = 31536000 - SESSIONSTIMEOUT = 10 configObj = { 'wok': { + 'plugin_class': 'KimchiRoot', 'enable': True, - 'plugin_class': "KimchiRoot", - 'uri': '/%s' % paths.plugin_dir, - 'extra_auth_api_class': "control.sub_nodes" + 'uri': '/plugins/kimchi', + 'extra_auth_api_class': 'control.sub_nodes' }, '/': { 'tools.trailing_slash.on': False, @@ -191,79 +97,73 @@ class ConfigTests(unittest.TestCase): 'tools.wokauth.on': True }, '/novnc': { - 'tools.staticdir.on': True, + 'tools.wokauth.on': True, + 'tools.nocache.on': True, 'tools.staticdir.dir': paths.novnc_dir, + 'tools.staticdir.on': True + }, + '/spice-html5': { + 'tools.wokauth.on': True, 'tools.nocache.on': True, - 'tools.wokauth.on': True + 'tools.staticdir.dir': paths.spice_dir, + 'tools.staticdir.on': True }, '/spice_auto.html': { + 'tools.wokauth.on': True, + 'tools.nocache.on': True, 'tools.staticfile.on': True, 'tools.staticfile.filename': paths.spice_file, - 'tools.nocache.on': True, - 'tools.wokauth.on': True - }, - '/spice-html5': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': paths.spice_dir, - 'tools.nocache.on': True }, '/spice-html5/spice.css': { - 'tools.staticfile.on': True, - 'tools.staticfile.filename': paths.spice_css_file, + 'tools.wokauth.on': True, 'tools.nocache.on': True, - }, - '/ui/config/tab-ext.xml': { 'tools.staticfile.on': True, - 'tools.staticfile.filename': '%s/ui/config/tab -ext.xml' % - pluginPrefix, - 'tools.nocache.on': True + 'tools.staticfile.filename': paths.spice_css_file, }, - '/css': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/css' % pluginPrefix, - 'tools.expires.on': True, - 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False + '/help': { + 'tools.nocache.on': True, + 'tools.staticdir.dir': '%s/ui/pages/help' % pluginPrefix, + 'tools.staticdir.on': True }, '/js': { - 'tools.staticdir.on': True, + 'tools.wokauth.on': False, + 'tools.nocache.on': False, 'tools.staticdir.dir': '%s/ui/js' % pluginPrefix, 'tools.expires.on': True, 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False + 'tools.staticdir.on': True }, - '/libs': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/libs' % pluginPrefix, + '/css': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticdir.dir': '%s/ui/css' % pluginPrefix, 'tools.expires.on': True, 'tools.expires.secs': CACHEEXPIRES, - 'tools.nocache.on': False, - 'tools.wokauth.on': False, + 'tools.staticdir.on': True }, '/images': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/images' % pluginPrefix, + 'tools.wokauth.on': False, 'tools.nocache.on': False, - 'tools.wokauth.on': False + 'tools.staticdir.dir': '%s/ui/images' % pluginPrefix, + 'tools.staticdir.on': True }, '/data/screenshots': { - 'tools.staticdir.on': True, + 'tools.nocache.on': False, 'tools.staticdir.dir': get_screenshot_path(), - 'tools.nocache.on': False + 'tools.staticdir.on': True + }, + '/ui/config/tab-ext.xml': { + 'tools.nocache.on': True, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': '%s/ui/config/tab -ext.xml' % + pluginPrefix, }, '/data/debugreports': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': get_debugreports_path(), - 'tools.nocache.on': False, 'tools.wokauth.on': True, - 'tools.staticdir.content_types': {'xz': 'application/x-xz'} - }, - '/help': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': '%s/ui/pages/help' % pluginPrefix, - 'tools.nocache.on': True + 'tools.nocache.on': False, + 'tools.staticdir.dir': get_debugreports_path(), + 'tools.staticdir.content_types': {'xz': 'application/x-xz'}, + 'tools.staticdir.on': True } }
diff --git a/tests/test_config.py.in b/tests/test_config.py.in index b4b46e1..d1a8576 100644 --- a/tests/test_config.py.in +++ b/tests/test_config.py.in @@ -19,7 +19,7 @@
import unittest
-from wok.config import Paths, WokConfig +from wok.config import CACHEEXPIRES, Paths, WokConfig
get_prefix = None @@ -94,14 +94,121 @@ class ConfigTests(unittest.TestCase): }, '/favicon.ico': { 'tools.staticfile.on': True, - 'tools.staticfile.filename': - '%s/images/logo.ico' % paths.ui_dir + 'tools.staticfile.filename': '%s/images/logo.ico' % + paths.ui_dir }, '/robots.txt': { 'tools.staticfile.on': True, 'tools.staticfile.filename': '%s/robots.txt' % paths.ui_dir }, + '/libs': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticdir.dir': '%s/ui/libs' % paths.prefix, + 'tools.expires.on': True, + 'tools.expires.secs': CACHEEXPIRES, + 'tools.staticdir.on': True + }, + '/css': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticdir.dir': '%s/ui/css' % paths.prefix, + 'tools.expires.on': True, + 'tools.expires.secs': CACHEEXPIRES, + 'tools.staticdir.on': True + }, + '/js': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticdir.dir': '%s/ui/js' % paths.prefix, + 'tools.expires.on': True, + 'tools.expires.secs': CACHEEXPIRES, + 'tools.staticdir.on': True + }, + '/images': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticdir.dir': '%s/ui/images' % paths.prefix, + 'tools.staticdir.on': True + }, + '/fonts/fontawesome-webfont.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/fontawesome-webfont.ttf' % paths.fontawesome_dir + }, + '/fonts/OpenSans-LightItalic.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-LightItalic.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-Bold.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-Bold.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-Italic.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-Italic.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-Semibold.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-Semibold.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-Light.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-Light.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-SemiboldItalic.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-SemiboldItalic.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-ExtraBold.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-ExtraBold.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-BoldItalic.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-BoldItalic.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-ExtraBoldItalic.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-ExtraBoldItalic.ttf' % paths.opensans_dir + }, + '/fonts/OpenSans-Regular.ttf': { + 'tools.wokauth.on': False, + 'tools.nocache.on': False, + 'tools.staticfile.on': True, + 'tools.staticfile.filename': + '%s/OpenSans-Regular.ttf' % paths.opensans_dir + } }
- wok_config = WokConfig.wok_config + wok_config = WokConfig() self.assertEquals(wok_config, configObj)