def validate_html(html, version): """ Validates HTML, and, if tag_validator is not None, also validates its contained tags. Might raise: HtmlCommentError InvalidHtmlTagError NestedHtmlTagError UnsupportedHtmlTag Use try/except in models clean method. """ tags = extract_active_tags(html) for tag in tags: tag_is_allowed(tag, version)
def test_extract_tags(self, html_file, html_file_tags): assert extract_active_tags(html_file) == html_file_tags
def test_closing_unopened_tag(self): with pytest.raises(InvalidHtmlTagError): _ = extract_active_tags("><p>My paragraph")
def test_unopened_comment(self): with pytest.raises(HtmlCommentError): _ = extract_active_tags("-->")
def test_unclosed_comment(self): with pytest.raises(HtmlCommentError): _ = extract_active_tags("<!-- <title>Fail</title>")
def test_unclosed_tag(self): with pytest.raises(InvalidHtmlTagError): _ = extract_active_tags("<html")
def test_nested_tag(self): with pytest.raises(NestedHtmlTagError): _ = extract_active_tags("<<html>")