mirror of
https://github.com/dbv111m/musicgrabber.git
synced 2026-10-19 01:31:29 -05:00
WIP: add test files and update .gitignore
This commit is contained in:
1 parent
5942e4da30
commit
ad92158bd9
2 files changed
+146
-1
No files matched your search
+3
-1
@@ -41,4 +41,6 @@ Thumbs.db
|
||||
.claude/
|
||||
|
||||
# Working docs (AI-managed project notes, plans, reviews)
|
||||
docs/
|
||||
docs/test_bot.py
|
||||
test_coverage.py
|
||||
tests/
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
"""
|
||||
Tests for MusicGrabber Telegram Bot and Download functionality
|
||||
|
||||
These tests verify:
|
||||
1. Monochrome fallback to YouTube when API fails
|
||||
2. Telegram chat_id tracking
|
||||
3. File sending logic
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, '/app')
|
||||
|
||||
|
||||
class TestMonochromeFallback:
|
||||
"""Tests for Monochrome to YouTube fallback"""
|
||||
|
||||
def test_fallback_on_403(self):
|
||||
"""When Monochrome returns 403, should fallback to YouTube"""
|
||||
from downloads import _process_monochrome_download
|
||||
|
||||
# This test verifies the function structure
|
||||
# In real scenario, would mock httpx to return 403
|
||||
assert callable(_process_monochrome_download)
|
||||
|
||||
def test_process_download_fallback_path(self):
|
||||
"""Verify fallback logic exists in process_download"""
|
||||
# The fallback logic is in process_download function
|
||||
from downloads import process_download
|
||||
assert callable(process_download)
|
||||
|
||||
|
||||
class TestTelegramChatId:
|
||||
"""Tests for Telegram chat_id tracking"""
|
||||
|
||||
def test_download_request_model(self):
|
||||
"""Verify DownloadRequest accepts telegram_chat_id"""
|
||||
from models import DownloadRequest
|
||||
|
||||
# Test creating a request with telegram_chat_id
|
||||
req = DownloadRequest(
|
||||
video_id="test123",
|
||||
title="Test Song",
|
||||
artist="Test Artist",
|
||||
telegram_chat_id=123456789
|
||||
)
|
||||
assert req.telegram_chat_id == 123456789
|
||||
assert req.video_id == "test123"
|
||||
|
||||
def test_download_request_defaults(self):
|
||||
"""Verify telegram_chat_id defaults to None"""
|
||||
from models import DownloadRequest
|
||||
|
||||
req = DownloadRequest(
|
||||
video_id="test123",
|
||||
title="Test Song"
|
||||
)
|
||||
assert req.telegram_chat_id is None
|
||||
|
||||
|
||||
class TestFilePathTracking:
|
||||
"""Tests for file_path tracking in jobs"""
|
||||
|
||||
def test_job_has_file_path(self):
|
||||
"""Verify jobs table should have file_path column"""
|
||||
# This would be tested with actual DB migration
|
||||
# For now, verify the code uses file_path
|
||||
from downloads import _update_job
|
||||
assert callable(_update_job)
|
||||
|
||||
|
||||
class TestNotifications:
|
||||
"""Tests for notification system"""
|
||||
|
||||
def test_send_notification_import(self):
|
||||
"""Verify send_notification can be imported"""
|
||||
from notifications import send_notification
|
||||
assert callable(send_notification)
|
||||
|
||||
def test_send_audio_to_telegram_import(self):
|
||||
"""Verify send_audio_to_telegram can be imported"""
|
||||
from notifications import send_audio_to_telegram
|
||||
assert callable(send_audio_to_telegram)
|
||||
|
||||
def test_notification_message_building(self):
|
||||
"""Verify notification messages are built correctly"""
|
||||
from notifications import _build_notification_message
|
||||
|
||||
msg, subject = _build_notification_message(
|
||||
notification_type="single",
|
||||
title="Test Song",
|
||||
artist="Test Artist",
|
||||
source="youtube",
|
||||
status="completed"
|
||||
)
|
||||
assert "Test Song" in msg
|
||||
assert "Test Artist" in msg
|
||||
|
||||
|
||||
class TestDuplicateCheck:
|
||||
"""Tests for duplicate file checking"""
|
||||
|
||||
def test_unicode_apostrophe_normalization(self):
|
||||
"""Verify different apostrophe variants are handled"""
|
||||
from utils import check_duplicate, sanitize_filename
|
||||
|
||||
# Test that sanitize_filename normalizes apostrophes
|
||||
s1 = sanitize_filename("It's a test")
|
||||
s2 = sanitize_filename("It\u2019s a test")
|
||||
|
||||
# Both should have standard apostrophe
|
||||
assert "'" in s1 or s1 == s2
|
||||
|
||||
|
||||
class TestSearchFunctionality:
|
||||
"""Tests for search functionality"""
|
||||
|
||||
def test_search_youtube(self):
|
||||
"""Verify YouTube search works"""
|
||||
from youtube import search_youtube
|
||||
|
||||
results = search_youtube("test", limit=1)
|
||||
assert isinstance(results, list)
|
||||
|
||||
|
||||
class TestBotSearch:
|
||||
"""Tests for Telegram bot search"""
|
||||
|
||||
def test_search_music_function(self):
|
||||
"""Verify bot search function exists"""
|
||||
from telegram_bot import search_music
|
||||
assert callable(search_music)
|
||||
|
||||
def test_download_track_function(self):
|
||||
"""Verify bot download function exists"""
|
||||
from telegram_bot import download_track
|
||||
assert callable(download_track)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
Reference in new issue
Block a user