mirror of
https://gitverse.ru/kpa39l/chronicle.nixg.ru.git
synced 2026-09-29 09:55:08 +00:00
127 lines
3.8 KiB
Python
127 lines
3.8 KiB
Python
"""Tests for Pydantic models."""
|
|
|
|
import pytest
|
|
from datetime import datetime
|
|
|
|
from app.models import PostData, MediaFile, MediaType, ArchiveRequest
|
|
|
|
|
|
class TestMediaFile:
|
|
"""Test MediaFile model."""
|
|
|
|
def test_create_media_file(self):
|
|
"""Test creating a MediaFile instance."""
|
|
media = MediaFile(
|
|
filename="test.jpg",
|
|
type=MediaType.PHOTO,
|
|
caption="Test caption",
|
|
size=1024,
|
|
)
|
|
assert media.filename == "test.jpg"
|
|
assert media.type == "photo"
|
|
assert media.caption == "Test caption"
|
|
assert media.size == 1024
|
|
assert media.is_too_large is False
|
|
|
|
def test_media_file_too_large(self):
|
|
"""Test MediaFile with is_too_large flag."""
|
|
media = MediaFile(
|
|
filename="large.mp4",
|
|
type="video",
|
|
size=500_000_000,
|
|
is_too_large=True,
|
|
)
|
|
assert media.is_too_large is True
|
|
|
|
|
|
class TestPostData:
|
|
"""Test PostData model."""
|
|
|
|
def test_create_post_data(self):
|
|
"""Test creating a PostData instance."""
|
|
post = PostData(
|
|
message_id=12345,
|
|
date=datetime(2024, 2, 19, 14, 30, 0),
|
|
text="Test message",
|
|
author="Test Channel",
|
|
channel_username="test_channel",
|
|
)
|
|
assert post.message_id == 12345
|
|
assert post.text == "Test message"
|
|
assert post.author == "Test Channel"
|
|
assert post.has_media() is False
|
|
|
|
def test_post_with_media(self):
|
|
"""Test PostData with media files."""
|
|
post = PostData(
|
|
message_id=12345,
|
|
date=datetime.now(),
|
|
text="Test",
|
|
author="Channel",
|
|
channel_username="channel",
|
|
media_files=[
|
|
MediaFile(filename="photo.jpg", type="photo", size=1024)
|
|
],
|
|
)
|
|
assert post.has_media() is True
|
|
assert post.has_downloaded_media() is True
|
|
|
|
def test_post_bundle_dir(self):
|
|
"""Test bundle_dir property."""
|
|
post = PostData(
|
|
message_id=99999,
|
|
date=datetime.now(),
|
|
text="Test",
|
|
author="Channel",
|
|
channel_username="channel",
|
|
)
|
|
assert post.bundle_dir == "99999"
|
|
assert post.index_path == "99999/index.md"
|
|
|
|
def test_post_with_reply_and_repost(self):
|
|
"""Test PostData with reply_to and repost_from."""
|
|
post = PostData(
|
|
message_id=12345,
|
|
date=datetime.now(),
|
|
text="Test",
|
|
author="Channel",
|
|
channel_username="channel",
|
|
reply_to=12340,
|
|
repost_from=10000,
|
|
repost_channel="Original Channel",
|
|
)
|
|
assert post.reply_to == 12340
|
|
assert post.repost_from == 10000
|
|
assert post.repost_channel == "Original Channel"
|
|
|
|
|
|
class TestArchiveRequest:
|
|
"""Test ArchiveRequest model."""
|
|
|
|
def test_minimal_request(self):
|
|
"""Test minimal archive request."""
|
|
req = ArchiveRequest(channel="dedinit")
|
|
assert req.channel == "dedinit"
|
|
assert req.limit is None
|
|
assert req.force is False
|
|
|
|
def test_full_request(self):
|
|
"""Test archive request with all options."""
|
|
req = ArchiveRequest(
|
|
channel="test_channel",
|
|
output_dir="/tmp/archive",
|
|
limit=100,
|
|
from_message_id=5000,
|
|
force=True,
|
|
)
|
|
assert req.channel == "test_channel"
|
|
assert req.output_dir == "/tmp/archive"
|
|
assert req.limit == 100
|
|
assert req.from_message_id == 5000
|
|
assert req.force is True
|
|
|
|
def test_channel_with_at(self):
|
|
"""Test channel username with @ prefix."""
|
|
req = ArchiveRequest(channel="@dedinit")
|
|
assert req.channel == "@dedinit"
|