Module: check_mk
Branch: master
Commit: 660fefb0fd65921ee911c7a1acddc206a157d9e0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=660fefb0fd6592…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Thu Jan 12 09:43:45 2017 +0100
Refactoring htmllib: changed mechanics of javascript_file.
Change-Id: Icb03c65bc481baba5006363aeb4fca39d1aa3d42
---
tests/web/classes.py | 27 +++++++++++----------------
tests/web/test_htmllib_integration.py | 16 +++++++---------
web/htdocs/html_mod_python.py | 2 +-
web/htdocs/htmllib.py | 6 +++---
web/htdocs/valuespec.py | 2 +-
5 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/tests/web/classes.py b/tests/web/classes.py
index 895e8ab..1caaef7 100644
--- a/tests/web/classes.py
+++ b/tests/web/classes.py
@@ -777,12 +777,6 @@ class HTMLTester(object):
#raise NotImplementedError()
return "file/name/css_%s" % css
-
- def javascript_filename_for_browser(self, jsname):
- #raise NotImplementedError()
- return "file/name/js_%s" % jsname
-
-
def top_heading(self, title):
self.top_heading_left(title)
self.top_heading_right()
@@ -800,21 +794,22 @@ class HTMLTester(object):
return {"1": 1, "2": 2, "3": 3,}
-class GeneratorTester(HTMLTester, HTMLGenerator):
- def __init__(self):
- super(GeneratorTester, self).__init__()
- HTMLTester.__init__(self)
- HTMLGenerator.__init__(self)
+class HTMLCheck_MKTester(HTMLTester, html):
+
+ def javascript_filename_for_browser(self, jsname):
+ #raise NotImplementedError()
+ return "js/file/name/js_%s.js" % jsname
-class HTMLCheck_MKTester(HTMLTester, html):
- pass
-# def __init__(self):
-# super(HTMLCheck_MKTester, self).__init__()
class HTMLOrigTester(HTMLTester, DeprecatedRenderer):
- pass
+
+ def javascript_filename_for_browser(self, jsname):
+ #raise NotImplementedError()
+ return "file/name/js_%s" % jsname
+
+
diff --git a/tests/web/test_htmllib_integration.py
b/tests/web/test_htmllib_integration.py
index e8558fd..0c264b3 100644
--- a/tests/web/test_htmllib_integration.py
+++ b/tests/web/test_htmllib_integration.py
@@ -15,13 +15,8 @@ import i18n
# internal imports
from htmllib import html
from htmllib import HTMLGenerator, HTMLCheck_MK
-from tools import compare_html , gentest, compare_and_empty
-from classes import HTMLOrigTester, GeneratorTester, HTMLCheck_MKTester,
DeprecatedRenderer
-
-
-
-
-
+from tools import compare_html, gentest, compare_and_empty
+from classes import HTMLOrigTester, HTMLCheck_MKTester, DeprecatedRenderer
def test_select():
@@ -168,10 +163,11 @@ def test_text_input():
new.user_errors = {v: "(not) a test
error"}
gentest(old, new, lambda x:
x.text_input(v,d,c,l,i,s,a,**arg))
+
def test_generator():
old = HTMLOrigTester()
- new = GeneratorTester()
+ new = HTMLCheck_MKTester()
old.plug()
new.plug()
@@ -185,7 +181,9 @@ def test_generator():
gentest(old, new, lambda x: x.javascript("set_reload(0,
\'address\')"))
- gentest(old, new, lambda x: x.javascript_file("Test"))
+ old.javascript_file("Test")
+ new.javascript_file("js/Test.js")
+ compare_and_empty(old, new)
gentest(old, new, lambda x: x.play_sound("Test"))
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index abd5ab8..49eff00 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -329,7 +329,7 @@ class html_mod_python(htmllib.html):
for min_part in min_parts:
path_pattern = cmk.paths.omd_root + "%s" + rel_path + "/"
+ jsname + min_part + ".js"
if os.path.exists(path_pattern % "") or os.path.exists(path_pattern
% "/local"):
- filename_for_browser = '%s%s-%s' % (jsname, min_part,
cmk.__version__)
+ filename_for_browser = 'js/%s%s-%s.js' % (jsname, min_part,
cmk.__version__)
break
return filename_for_browser
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 35a019a..c9fdaf1 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -640,9 +640,9 @@ class HTMLGenerator(Escaper, OutputFunnel):
return self.write(self.render_javascript(code))
- def javascript_file(self, filename):
- """ <script type="text/javascript"
src="js/%(name)s.js"/>\n """
- return self.write(self._render_content_tag('script', '',
type_="text/javascript", src='js/%s.js' % filename))
+ def javascript_file(self, src):
+ """ <script type="text/javascript"
src="%(name)"/>\n """
+ return self.write(self._render_content_tag('script', '',
type_="text/javascript", src=src))
def render_img(self, src, **attrs):
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index e9410bf..f6d5ee8 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -4086,7 +4086,7 @@ class Color(ValueSpec):
if not value:
value = "#FFFFFF"
- html.javascript_file("colorpicker")
+ html.javascript_file("js/colorpicker.js")
# Holds the actual value for form submission
html.hidden_field(varprefix + "_value", value or '', varprefix
+ "_value", add_var = True)