'Tests the full suite of Mako best practices by running all of the
combinations of types of data and types of escaping through a Mako
template.
Additionally, validates the best practices themselves by validating
the expectations to ensure they can properly be unescaped and/or
parsed from json where applicable.'

def test_mako(self):

    test_dict = {'test_string': u'test-=&\\;\'"<>\u2603'.encode(encoding='utf-8'), 'test_tuple': (1, 2, 3), 'test_number': 3.5, 'test_bool': False}
    template = Template('\n                                                                <%!\n                                                                import    json\n                                                                from    openedx.core.djangolib.js_utils    import    (\n                                                                                dump_js_escaped_json,    js_escaped_string\n                                                                )\n                                                                %>\n                                                                <body>\n                                                                                <div\n                                                                                                data-test-dict=\'${json.dumps(test_dict)}\'\n                                                                                                data-test-string=\'${test_dict["test_string"]}\'\n                                                                                                data-test-tuple=\'${json.dumps(test_dict["test_tuple"])}\'\n                                                                                                data-test-number=\'${json.dumps(test_dict["test_number"])}\'\n                                                                                                data-test-bool=\'${json.dumps(test_dict["test_bool"])}\'\n                                                                                ></div>\n\n                                                                                <script>\n                                                                                                var    test_dict    =    ${test_dict    |    n,    dump_js_escaped_json}\n                                                                                                var    test_string    =    \'${test_dict["test_string"]    |    n,    js_escaped_string}\'\n                                                                                                var    test_none_string    =    \'${None    |    n,    js_escaped_string}\'\n                                                                                                var    test_tuple    =    ${test_dict["test_tuple"]    |    n,    dump_js_escaped_json}\n                                                                                                var    test_number    =    ${test_dict["test_number"]    |    n,    dump_js_escaped_json}\n                                                                                                var    test_bool    =    ${test_dict["test_bool"]    |    n,    dump_js_escaped_json}\n                                                                                                var    test_none_json    =    ${None    |    n,    dump_js_escaped_json}\n                                                                                </script>\n                                                                </body>\n                                                ', default_filters=['decode.utf8', 'h'])
    out = template.render(test_dict=test_dict)
    expected_json_for_html = '{&#34;test_bool&#34;:    false,    &#34;test_number&#34;:    3.5,    &#34;test_tuple&#34;:    [1,    2,    3],    &#34;test_string&#34;:    &#34;test-=&amp;\\\\;&#39;\\&#34;&lt;&gt;\\u2603&#34;}'
    expected_attr_json_for_html = (("data-test-dict='" + expected_json_for_html) + "'")
    self._validate_expectation_of_json_for_html(test_dict, expected_json_for_html)
    self.assertIn(expected_attr_json_for_html, out)
    self.assertIn(u"data-test-string='test-=&amp;\\;&#39;&#34;&lt;&gt;\u2603'", out)
    self.assertIn("data-test-tuple='[1,    2,    3]'", out)
    self.assertIn("data-test-number='3.5'", out)
    self.assertIn("data-test-bool='false'", out)
    expected_string_for_js_in_dict = 'test-=\\u0026\\\\;\'\\"\\u003c\\u003e\\u2603'
    self._validate_expectation_of_string_for_js(test_dict['test_string'], expected_string_for_js_in_dict)
    self.assertIn((('var    test_dict    =    {"test_bool":    false,    "test_number":    3.5,    "test_tuple":    [1,    2,    3],    "test_string":    "' + expected_string_for_js_in_dict) + '"}'), out)
    expected_string_for_js = 'test\\u002D\\u003D\\u0026\\u005C\\u003B\\u0027\\u0022\\u003C\\u003E\xe2\x98\x83'
    self._validate_expectation_of_string_for_js(test_dict['test_string'], expected_string_for_js)
    self.assertIn((("var    test_string    =    '" + expected_string_for_js.decode(encoding='utf-8')) + "'"), out)
    self.assertIn("var    test_none_string    =    ''", out)
    self.assertIn('var    test_tuple    =    [1,    2,    3]', out)
    self.assertIn('var    test_number    =    3.5', out)
    self.assertIn('var    test_bool    =    false', out)
    self.assertIn('var    test_none_json    =    null', out)
