vk_hackathon/tests/test_rendering.py
q e49e3417eb Add logviewer project and fix Docker imports
- Add logviewer/: Dozzle web UI (port 9999) + analyze.py CLI tool
- docker-compose.yml: add json-file logging with rotation and labels for index/search
- Fix Dockerfiles: COPY *.py . so all modules are included in image
- Convert all relative imports to flat absolute imports for Docker flat layout
- Rename index/schemas.py → index/index_schemas.py to avoid module name collision with search/schemas.py in test runner
- Update all tests to add service dir to sys.path and use flat imports

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-18 15:26:11 +03:00

110 lines
3.4 KiB
Python

"""Unit tests for index/rendering.py"""
import sys
import os
_INDEX_DIR = os.path.join(os.path.dirname(__file__), "..", "index")
sys.path.insert(0, _INDEX_DIR)
from cleaning import CleanedMessage
from rendering import render_page_content, render_dense_content, render_sparse_content
def _make_cleaned(**kwargs) -> CleanedMessage:
defaults = dict(
id="msg1",
sender_id="alice@example.com",
time=1700000000,
thread_sn=None,
text="",
parts=[],
mentions=[],
member_event_text="",
file_info=[],
is_system=False,
is_forward=False,
is_quote=False,
)
defaults.update(kwargs)
return CleanedMessage(**defaults)
class TestRenderPageContent:
def test_text_message(self):
msg = _make_cleaned(text="Hello world")
result = render_page_content(msg)
assert "alice@example.com" in result
assert "Hello world" in result
def test_quote_part(self):
msg = _make_cleaned(
parts=[{"type": "quote", "text": "[quote from bob]: original"}]
)
result = render_page_content(msg)
assert "[quote from bob]" in result
def test_forward_part(self):
msg = _make_cleaned(
parts=[{"type": "forward", "text": "[forwarded from channel]: content"}],
is_forward=True,
)
result = render_page_content(msg)
assert "forwarded" in result
def test_member_event(self):
msg = _make_cleaned(
member_event_text="[system: alice@x.com added to chat]",
is_system=True,
)
result = render_page_content(msg)
assert "added to chat" in result
def test_file_attachment(self):
msg = _make_cleaned(
file_info=[{"name": "report.pdf", "mime": "application/pdf", "url": "", "date": ""}]
)
result = render_page_content(msg)
assert "report.pdf" in result
class TestRenderDenseContent:
def test_includes_timestamp(self):
msg = _make_cleaned(text="test", time=1700000000)
result = render_dense_content(msg)
assert "2023-" in result # UTC date
def test_includes_sender(self):
msg = _make_cleaned(text="hi", sender_id="bob@corp.com")
result = render_dense_content(msg)
assert "sender:bob@corp.com" in result
def test_forward_marker(self):
msg = _make_cleaned(is_forward=True, parts=[{"type": "forward", "text": "[forwarded]: x"}])
result = render_dense_content(msg)
assert "type:forward" in result
def test_mentions_included(self):
msg = _make_cleaned(
text="hey",
mentions=["charlie@corp.com"],
)
result = render_dense_content(msg)
assert "charlie@corp.com" in result
class TestRenderSparseContent:
def test_includes_sender(self):
msg = _make_cleaned(text="hello")
result = render_sparse_content(msg)
assert "alice@example.com" in result
def test_includes_mentions(self):
msg = _make_cleaned(text="ping", mentions=["dave@corp.com"])
result = render_sparse_content(msg)
assert "dave@corp.com" in result
def test_includes_filename(self):
msg = _make_cleaned(
file_info=[{"name": "budget.xlsx", "mime": "", "url": "", "date": ""}]
)
result = render_sparse_content(msg)
assert "budget.xlsx" in result