Implement Pravda: Truth Social to Discord relay service
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m59s
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m59s
- Add core modules: database (SQLite), media (ffmpeg), discord (webhook), poller (truthbrush), server (FastAPI) - Support video transcoding to H.264/AAC with automatic size management - Handle message splitting for Discord limits (2000 chars, 10 attachments) - Include interactive buttons (Delete, View Raw, Original Post) - Add Dockerfile with ffmpeg and entrypoint script - Add Gitea Actions workflow for CI/CD - Configure code style tools (black, ruff, mypy) - Include basic unit tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
60
tests/test_discord.py
Normal file
60
tests/test_discord.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Tests for the Discord module."""
|
||||
|
||||
from src.discord import split_content, build_components
|
||||
|
||||
|
||||
def test_split_content_short() -> None:
|
||||
"""Test that short content is not split."""
|
||||
content = "Hello, world!"
|
||||
result = split_content(content)
|
||||
assert len(result) == 1
|
||||
assert result[0] == content
|
||||
|
||||
|
||||
def test_split_content_long() -> None:
|
||||
"""Test that long content is split correctly."""
|
||||
content = "x" * 2500
|
||||
result = split_content(content, max_length=2000)
|
||||
assert len(result) == 2
|
||||
assert "[Part 1/2]" in result[0]
|
||||
assert "[Part 2/2]" in result[1]
|
||||
|
||||
|
||||
def test_split_content_preserves_newlines() -> None:
|
||||
"""Test that content is split on newlines when possible."""
|
||||
content = "\n".join(["Line " + str(i) for i in range(100)])
|
||||
result = split_content(content, max_length=500)
|
||||
assert len(result) > 1
|
||||
# Each part should have complete lines
|
||||
for part in result:
|
||||
assert "Line" in part
|
||||
|
||||
|
||||
def test_build_components() -> None:
|
||||
"""Test that components are built correctly."""
|
||||
components = build_components(
|
||||
post_url="https://truthsocial.com/@user/posts/123",
|
||||
post_id="123",
|
||||
raw_json='{"id": "123"}',
|
||||
)
|
||||
|
||||
assert len(components) == 1
|
||||
assert components[0]["type"] == 1 # Action Row
|
||||
|
||||
buttons = components[0]["components"]
|
||||
assert len(buttons) == 3
|
||||
|
||||
# Delete button
|
||||
assert buttons[0]["type"] == 2
|
||||
assert buttons[0]["style"] == 4 # Danger
|
||||
assert buttons[0]["label"] == "Delete"
|
||||
|
||||
# View Raw button
|
||||
assert buttons[1]["type"] == 2
|
||||
assert buttons[1]["style"] == 2 # Secondary
|
||||
assert buttons[1]["label"] == "View Raw"
|
||||
|
||||
# Original Post button (link)
|
||||
assert buttons[2]["type"] == 2
|
||||
assert buttons[2]["style"] == 5 # Link
|
||||
assert buttons[2]["url"] == "https://truthsocial.com/@user/posts/123"
|
||||
Reference in New Issue
Block a user