Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Apr 13, 2024
1 parent 76c30c1 commit 79e65cd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
19 changes: 0 additions & 19 deletions tests/basic_rendering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
br,
input,
a,
DangerousRawHtml,
)


Expand Down Expand Up @@ -249,21 +248,3 @@ def test_boolean_tag_attributes_false():
Attributes with value `False` are skipped
"""
assert str(input(readonly=False)) == "<input/>"


def test_dangerous_raw_html():
"""
Is raw HTML rendered correctly?
"""
assert str(DangerousRawHtml("<script>alert(1)</script>")) \
== "<script>alert(1)</script>"

assert str(
html(
DangerousRawHtml("<script>alert(1)</script>")
)
) == "\n".join([
"<html>",
" <script>alert(1)</script>",
"</html>",
])
3 changes: 2 additions & 1 deletion tests/end_to_end/flask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ def test_failed_to_stringify(client: FlaskClient):
assert "**HINT:** if you're using Flask" in str(exception_info.value)


if __name__ == '__main__':
# Ignore coverage since this won't be used when running tests automatically
if __name__ == '__main__': # pragma: no cover
app.run(debug=True)
33 changes: 33 additions & 0 deletions tests/raw_html_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
# Tests / Raw HTML Test
Test cases for `DangerousRawHtml` tag
"""
import pytest
from pyhtml import DangerousRawHtml, html


def test_dangerous_raw_html():
"""
Is raw HTML rendered correctly?
"""
assert str(DangerousRawHtml("<script>alert(1)</script>")) \
== "<script>alert(1)</script>"

assert str(
html(
DangerousRawHtml("<script>alert(1)</script>")
)
) == "\n".join([
"<html>",
" <script>alert(1)</script>",
"</html>",
])


def test_raw_html_not_callable():
"""
`DangerousRawHtml` elements should not be callable.
"""
with pytest.raises(TypeError):
DangerousRawHtml("")()

0 comments on commit 79e65cd

Please sign in to comment.