403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.216
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/www/html/api.turmansolutions.ai/tests/unit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/www/html/api.turmansolutions.ai/tests/unit/test_citations.py
"""Unit tests for inline-citation normalization."""

from app.utilities.citations import normalize_citations

CANONICAL = '<sup class="tsai-citation"><a href="{url}">[{n}]</a></sup>'
URL = "https://www.theguardian.com/us-news/2026/jun/21/utah-wildfire-extreme-heat"


def test_markdown_double_bracket_in_html_block_is_converted():
    # The real bug: an HTML body leaves markdown citations unrendered.
    html = f'<p>Hotter conditions are expected [[1]]({URL}). More.</p>'
    out = normalize_citations(html)
    assert out == f'<p>Hotter conditions are expected {CANONICAL.format(url=URL, n="1")}. More.</p>'
    assert "[[1]]" not in out
    assert f"]({URL})" not in out


def test_markdown_single_bracket_is_converted():
    html = f'<p>text [2]({URL}) end.</p>'
    out = normalize_citations(html)
    assert out == f'<p>text {CANONICAL.format(url=URL, n="2")} end.</p>'


def test_rendered_bare_anchor_is_wrapped_in_sup():
    # A markdown body renders [[1]](url) to a bare anchor; we superscript it.
    html = f'<p>text <a href="{URL}">[1]</a> end.</p>'
    out = normalize_citations(html)
    assert out == f'<p>text {CANONICAL.format(url=URL, n="1")} end.</p>'


def test_already_canonical_is_idempotent():
    html = f'<p>text {CANONICAL.format(url=URL, n="3")} end.</p>'
    assert normalize_citations(html) == html
    # And running twice from a leaked form is stable.
    leaked = f'<p>text [[3]]({URL}) end.</p>'
    once = normalize_citations(leaked)
    assert normalize_citations(once) == once


def test_plain_sup_anchor_is_recanonicalized():
    html = f'<p>text <sup><a href="{URL}">[4]</a></sup> end.</p>'
    out = normalize_citations(html)
    assert out == f'<p>text {CANONICAL.format(url=URL, n="4")} end.</p>'


def test_reference_list_title_links_are_untouched():
    # Reference-list entries link the source TITLE, not a bracketed number.
    html = (
        '<ol>'
        f'<li><a href="{URL}">Utah wildfire forces evacuation</a> — {URL}</li>'
        '</ol>'
    )
    assert normalize_citations(html) == html


def test_multiple_citations_in_one_paragraph():
    u2 = "https://www.reuters.com/world/x"
    html = f'<p>a [[1]]({URL}) b [[2]]({u2}) c.</p>'
    out = normalize_citations(html)
    assert CANONICAL.format(url=URL, n="1") in out
    assert CANONICAL.format(url=u2, n="2") in out


def test_empty_and_no_citation_input():
    assert normalize_citations("") == ""
    assert normalize_citations("<p>No citations here.</p>") == "<p>No citations here.</p>"

Youez - 2016 - github.com/yon3zu
LinuXploit