polygrapher / tests /test_post_process.py
dhruv575
Update and clean
c4a298e
"""Tests for post_process utility functions."""
from app.post_process import (
append_signup_modal_to_links,
convert_polymarket_links,
minify_html,
)
class TestConvertPolymarketLinks:
def test_no_api_key_returns_unchanged(self):
html = '<a href="https://polymarket.com/event/foo">Link</a>'
result = convert_polymarket_links(html, api_key=None)
assert result == html
def test_empty_api_key_returns_unchanged(self):
html = '<a href="https://polymarket.com/event/foo">Link</a>'
result = convert_polymarket_links(html, api_key="")
assert result == html
def test_no_polymarket_links_returns_unchanged(self):
html = '<a href="https://example.com">Link</a>'
result = convert_polymarket_links(html, api_key="test-key")
assert result == html
class TestAppendSignupModal:
def test_appends_modal_params(self):
html = '<a href="https://polymarket.com/event/foo">Link</a>'
result = append_signup_modal_to_links(html)
assert "modal=signup" in result
assert "td=9" in result
def test_no_polymarket_links_unchanged(self):
html = '<a href="https://example.com">Link</a>'
result = append_signup_modal_to_links(html)
assert result == html
def test_preserves_existing_query_params(self):
html = '<a href="https://polymarket.com/event/foo?bar=1">Link</a>'
result = append_signup_modal_to_links(html)
assert "bar=1" in result
assert "modal=signup" in result
class TestMinifyHtml:
def test_removes_font_face_styles(self):
html = """<html><head>
<style>@font-face { font-family: "Test"; src: url("test.woff2"); }</style>
</head><body><p>Hello</p></body></html>"""
result = minify_html(html)
assert "@font-face" not in result
assert "Hello" in result
def test_preserves_content(self):
html = "<html><body><p>Important content</p></body></html>"
result = minify_html(html)
assert "Important content" in result
def test_output_is_smaller_or_equal(self):
html = """<html><head>
<style>@font-face { font-family: "Test"; src: url("test.woff2"); }</style>
</head><body>
<p> Some content </p>
</body></html>"""
result = minify_html(html)
assert len(result) <= len(html)