forked from retoor/devplacepy
docs: document server-side rendering pipeline, response timing middleware, and Telegram pairing API
- Add comprehensive documentation for backend content rendering in AGENTS.md, detailing the new `render_content` and `render_title` Jinja globals built on mistune with media processing, emoji shortcodes, and XSS protection
- Document the `X-Response-Time` header and bottom-left render time indicator in README.md
- Update bot token pricing documentation to clarify fallback vs gateway cost headers
- Add `email_accounts` to soft-delete tables and `idx_users_role` composite index in database schema
- Implement `telegram_pairings` and `telegram_links` table creation with column migration and indexes
- Add `/profile/{username}/telegram` endpoint to docs API with request/unpair actions
- Register `TelegramService` in main.py lifespan and add `response_timing` middleware emitting `X-Response-Time` header
- Introduce `TelegramPairForm` model and `guard_public_host_sync` synchronous host validation function
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.services.telegram.format import (
|
||||
markdown_to_telegram_html,
|
||||
split_for_telegram,
|
||||
)
|
||||
|
||||
|
||||
def test_markdown_basic_formatting():
|
||||
out = markdown_to_telegram_html("Hello **bold** and _em_ and `code`")
|
||||
assert "<b>bold</b>" in out
|
||||
assert "<i>em</i>" in out
|
||||
assert "<code>code</code>" in out
|
||||
|
||||
|
||||
def test_markdown_link_kept():
|
||||
out = markdown_to_telegram_html("see [docs](https://example.com/x)")
|
||||
assert '<a href="https://example.com/x">docs</a>' in out
|
||||
|
||||
|
||||
def test_markdown_escapes_special_characters():
|
||||
out = markdown_to_telegram_html("a < b & c > d")
|
||||
assert "<" in out and "&" in out and ">" in out
|
||||
|
||||
|
||||
def test_markdown_drops_unsupported_tags():
|
||||
out = markdown_to_telegram_html("# Heading\n\ntext")
|
||||
assert "<h1>" not in out
|
||||
assert "<b>Heading</b>" in out
|
||||
|
||||
|
||||
def test_split_respects_limit():
|
||||
chunks = split_for_telegram("a" * 5000, limit=3900)
|
||||
assert all(len(chunk) <= 3900 for chunk in chunks)
|
||||
assert "".join(chunks) == "a" * 5000
|
||||
|
||||
|
||||
def test_split_short_text_single_chunk():
|
||||
assert split_for_telegram("hello") == ["hello"]
|
||||
|
||||
|
||||
def test_split_breaks_single_oversized_line():
|
||||
chunks = split_for_telegram("b" * 9000, limit=4000)
|
||||
assert all(len(chunk) <= 4000 for chunk in chunks)
|
||||
assert "".join(chunks) == "b" * 9000
|
||||
|
||||
|
||||
def test_split_empty_text_returns_single_empty_chunk():
|
||||
assert split_for_telegram("") == [""]
|
||||
|
||||
|
||||
def test_markdown_empty_input_is_empty():
|
||||
assert markdown_to_telegram_html("") == ""
|
||||
Reference in New Issue
Block a user