58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Basic tests for neo-pod-desktop
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src"))
|
|
|
|
from audio_converter import AudioConverter
|
|
from metadata_handler import MetadataHandler
|
|
|
|
|
|
class TestAudioConverter(unittest.TestCase):
|
|
"""Test audio converter functionality"""
|
|
|
|
def test_sanitize_filename(self):
|
|
"""Test filename sanitization"""
|
|
converter = AudioConverter()
|
|
|
|
sanitized = converter._sanitize_filename('File: with "invalid" chars?')
|
|
self.assertEqual(sanitized, 'File_ with _invalid_ chars_')
|
|
|
|
long_name = "A" * 150
|
|
sanitized = converter._sanitize_filename(long_name)
|
|
self.assertEqual(len(sanitized), 100)
|
|
self.assertTrue(sanitized.endswith('...'))
|
|
|
|
|
|
class TestMetadataHandler(unittest.TestCase):
|
|
"""Test metadata handler functionality"""
|
|
|
|
@patch('requests.get')
|
|
def test_download_thumbnail(self, mock_get):
|
|
"""Test thumbnail download"""
|
|
mock_response = MagicMock()
|
|
mock_response.raise_for_status.return_value = None
|
|
mock_response.content = b'fake_image_data'
|
|
mock_get.return_value = mock_response
|
|
|
|
with patch('PIL.Image.open') as mock_image_open:
|
|
mock_image = MagicMock()
|
|
mock_image.save.return_value = None
|
|
mock_image_open.return_value = mock_image
|
|
|
|
handler = MetadataHandler()
|
|
result = handler.download_thumbnail("https://example.com/image.jpg")
|
|
|
|
self.assertIsNotNone(result)
|
|
mock_get.assert_called_once_with("https://example.com/image.jpg", timeout=10)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|