File size: 2,402 Bytes
c4a298e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""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)