'Test _check_mako_file_is_safe tests for proper use of Text() and Html().'

@data({'expression': textwrap.dedent('\n                                                                                <%\n                                                                                                a_link_start    =    \'<a    class="link-courseURL"    rel="external"    href="\'\n                                                                                                a_link_end    =    \'">\'    +    _("your    course    summary    page")    +    \'</a>\'\n                                                                                                a_link    =    a_link_start    +    lms_link_for_about_page    +    a_link_end\n                                                                                                text    =    _("Introductions,    prerequisites,    FAQs    that    are    used    on    %s    (formatted    in    HTML)")    %    a_link\n                                                                                %>\n                                                                '), 'rule': [Rules.python_wrap_html, Rules.python_concat_html, Rules.python_wrap_html]}, {'expression': textwrap.dedent('\n                                                                                ${"Mixed    {span_start}text{span_end}".format(\n                                                                                                span_start=HTML("<span>"),\n                                                                                                span_end=HTML("</span>"),\n                                                                                )}\n                                                                '), 'rule': Rules.python_requires_html_or_text}, {'expression': textwrap.dedent('\n                                                                                ${Text("Mixed    {span_start}text{span_end}").format(\n                                                                                                span_start=HTML("<span>"),\n                                                                                                span_end=HTML("</span>"),\n                                                                                )}\n                                                                '), 'rule': None}, {'expression': textwrap.dedent('\n                                                                                ${"Mixed    {span_start}{text}{span_end}".format(\n                                                                                                span_start=HTML("<span>"),\n                                                                                                text=Text("This    should    still    break."),\n                                                                                                span_end=HTML("</span>"),\n                                                                                )}\n                                                                '), 'rule': Rules.python_requires_html_or_text}, {'expression': textwrap.dedent('\n                                                                                ${Text("Mixed    {link_start}text{link_end}".format(\n                                                                                                link_start=HTML("<a    href=\'{}\'>").format(url),\n                                                                                                link_end=HTML("</a>"),\n                                                                                ))}\n                                                                '), 'rule': [Rules.python_close_before_format, Rules.python_requires_html_or_text]}, {'expression': textwrap.dedent('\n                                                                                ${Text("Mixed    {link_start}text{link_end}").format(\n                                                                                                link_start=HTML("<a    href=\'{}\'>".format(url)),\n                                                                                                link_end=HTML("</a>"),\n                                                                                )}\n                                                                '), 'rule': Rules.python_close_before_format}, {'expression': textwrap.dedent('\n                                                                                ${"Mixed    {span_start}text{span_end}".format(\n                                                                                                span_start="<span>",\n                                                                                                span_end="</span>",\n                                                                                )}\n                                                                '), 'rule': [Rules.python_wrap_html, Rules.python_wrap_html]}, {'expression': textwrap.dedent('\n                                                                                ${Text(_("String    with    multiple    lines    "\n                                                                                                "{link_start}unenroll{link_end}    "\n                                                                                                "and    final    line")).format(\n                                                                                                                link_start=HTML(\n                                                                                                                                \'<a    id="link__over_multiple_lines"    \'\n                                                                                                                                \'data-course-id="{course_id}"    \'\n                                                                                                                                \'href="#test-modal">\'\n                                                                                                                ).format(\n                                                                                                                                course_id=course_overview.id\n                                                                                                                ),\n                                                                                                                link_end=HTML(\'</a>\'),\n                                                                                )}\n                                                                '), 'rule': None}, {'expression': "${'<span></span>'}", 'rule': Rules.python_wrap_html}, {'expression': "${'Embedded    HTML    <strong></strong>'}", 'rule': Rules.python_wrap_html}, {'expression': "${    HTML('<span></span>')    }", 'rule': None}, {'expression': "${HTML(render_entry(map['entries'],    child))}", 'rule': None}, {'expression': "${    '<span></span>'    +    'some    other    text'    }", 'rule': [Rules.python_concat_html, Rules.python_wrap_html]}, {'expression': "${    HTML('<span>missing    closing    parentheses.</span>'    }", 'rule': Rules.python_parse_error}, {'expression': "${'Rock    &amp;    Roll'}", 'rule': Rules.mako_html_entities}, {'expression': "${'Rock    &#38;    Roll'}", 'rule': Rules.mako_html_entities})
def test_check_mako_with_text_and_html(self, data):

    linter = MakoTemplateLinter()
    results = FileResults('')
    mako_template = textwrap.dedent('\n                                                <%page    expression_filter="h"/>\n                                                {expression}\n                                '.format(expression=data['expression']))
    linter._check_mako_file_is_safe(mako_template, results)
    self._validate_data_rules(data, results)
