def _fill_html_template(info, embed_js=True): as_json = json.dumps(info) as_html = get_html_template('surface_plot_template.html').safe_substitute({ 'INSERT_STAT_MAP_JSON_HERE': as_json, 'INSERT_PAGE_TITLE_HERE': info["title"] or "Surface plot" }) as_html = add_js_lib(as_html, embed_js=embed_js) return SurfaceView(as_html)
def test_add_js_lib(): html = js_plotting_utils.get_html_template('surface_plot_template.html') cdn = js_plotting_utils.add_js_lib(html, embed_js=False) assert "decodeBase64" in cdn assert _normalize_ws("""<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script src="https://cdn.plot.ly/plotly-gl3d-latest.min.js"></script> """) in _normalize_ws(cdn) inline = _normalize_ws(js_plotting_utils.add_js_lib(html, embed_js=True)) assert _normalize_ws("""/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */""") in inline assert _normalize_ws("""** * plotly.js (gl3d - minified)""") in inline assert "decodeBase64" in inline
def test_add_js_lib(): """Tests for function add_js_lib. Checks that the html page contains the javascript code. """ html = get_html_template('surface_plot_template.html') cdn = add_js_lib(html, embed_js=False) assert "decodeBase64" in cdn assert _normalize_ws("""<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"> </script> <script src="https://cdn.plot.ly/plotly-gl3d-latest.min.js"></script> """) in _normalize_ws(cdn) inline = _normalize_ws(add_js_lib(html, embed_js=True)) assert _normalize_ws("""/*! jQuery v3.6.0 | (c) OpenJS Foundation and other contributors | jquery.org/license */""") in inline assert _normalize_ws("""** * plotly.js (gl3d - minified)""") in inline assert "decodeBase64" in inline
def test_add_js_lib(): html = js_plotting_utils.get_html_template('surface_plot_template.html') cdn = js_plotting_utils.add_js_lib(html, embed_js=False) assert "decodeBase64" in cdn assert _normalize_ws("""<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script src="https://cdn.plot.ly/plotly-gl3d-latest.min.js"></script> """) in _normalize_ws(cdn) inline = _normalize_ws(js_plotting_utils.add_js_lib(html, embed_js=True)) assert _normalize_ws("""/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */""") in inline assert _normalize_ws("""** * plotly.js (gl3d - minified) v1.38.3 * Copyright 2012-2018, Plotly, Inc. * All rights reserved. * Licensed under the MIT license */ """) in inline assert "decodeBase64" in inline