Exemplo n.º 1
0
def test_parse_text_body():
    body_html = """
<div class="field-item even">
    <p>Test Body.</p>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """Test Body."""
Exemplo n.º 2
0
def test_parse_body_with_br():
    body_html = """
<div class="field-item even">
    <p>Line1<br>Line2</p>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """Line1\nLine2"""
Exemplo n.º 3
0
def test_parse_body_with_image():
    body_html = """
<div class="field-item even">
    <p>Test Body.</p>
    <img src="https://example.com/test.jpg"></img>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """Test Body.\n<a href="https://example.com/test.jpg">image</a>"""
Exemplo n.º 4
0
def test_parse_unordered_list():
    body_html = """
<div class="field-item even">
    <ul>
        <li>item1</li>
        <li>item2</li>
    </ul>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """  ◦ item1\n  ◦ item2"""
Exemplo n.º 5
0
def test_parse_email():
    body_html = """
<div>
    <script type="text/javascript">
    <!--//--><![CDATA[// ><!--
    eval(unescape(''%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%61%69%6c%40%67%6d%61%69%6c%2e%63%6f%6d%22%3e%6d%61%69%6c%40%67%6d%61%69%6c%2e%63%6f%6d%3c%2f%61%3e%27%29%3b''))
    //--><!]]>
    </script>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """<a href="mailto:[email protected]">[email protected]</a>"""
Exemplo n.º 6
0
def test_parse_table():
    body_html = """
<div class="field-item even">
    <table>
        <tr>
            <td>A</td>
            <td>B</td>
        </tr> 
        <tr>
            <td>C</td>
            <td>D</td>
        </tr> 
    </table>
</div>
"""
    bs = BeautifulSoup(body_html, 'html.parser')
    body_element = bs.findChild()

    parsed_body = forum._parse_comment_body(body_element)
    print(parsed_body.to_telegram_html())

    result = parsed_body.to_telegram_html()
    assert result == """A | B\nC | D"""