diff --git a/tests/test_media_upload.py b/tests/test_media_upload.py index 02bb328..3c2fd01 100644 --- a/tests/test_media_upload.py +++ b/tests/test_media_upload.py @@ -74,6 +74,31 @@ def create_test_heic(width=800, height=600): return buffer.getvalue() +def create_test_mpo(width=800, height=600): + """ + Generate test MPO (Multi-Picture Object) image + + MPO format is used by iPhones for depth/portrait photos. It contains + multiple JPEG images in one file. For testing, we create a simple MPO + with a single frame. + + Args: + width: Image width in pixels + height: Image height in pixels + + Returns: + Bytes of MPO image data + """ + # Create a simple RGB image + img = Image.new('RGB', (width, height), color='green') + + # Save as MPO (Pillow will handle this correctly) + buffer = io.BytesIO() + img.save(buffer, format='MPO', quality=95) + buffer.seek(0) + return buffer.getvalue() + + class TestImageValidation: """Test validate_image function""" @@ -236,6 +261,54 @@ class TestHEICSupport: assert saved_img.format == 'JPEG' +class TestMPOSupport: + """Test MPO (Multi-Picture Object) image format support (v1.5.0 Phase 5)""" + + def test_mpo_detection_and_conversion(self): + """Test MPO file is detected and converted to JPEG""" + mpo_data = create_test_mpo(800, 600) + file_data, mime_type, width, height = validate_image(mpo_data, 'test.mpo') + + # Should be converted to JPEG + assert mime_type == 'image/jpeg' + assert width == 800 + assert height == 600 + # Verify it's actually JPEG by opening it + img = Image.open(io.BytesIO(file_data)) + assert img.format == 'JPEG' + # Note: MPO with single frame may have identical bytes to JPEG + # The important part is the format detection and MIME type correction + + def test_mpo_dimensions_preserved(self): + """Test MPO conversion preserves dimensions""" + mpo_data = create_test_mpo(1024, 768) + file_data, mime_type, width, height = validate_image(mpo_data, 'photo.mpo') + + assert width == 1024 + assert height == 768 + assert mime_type == 'image/jpeg' + + def test_mpo_full_upload_flow(self, app): + """Test complete MPO upload through save_media""" + mpo_data = create_test_mpo(800, 600) + + with app.app_context(): + media_info = save_media(mpo_data, 'iphone_portrait.mpo') + + # Should be saved as JPEG + assert media_info['mime_type'] == 'image/jpeg' + assert media_info['width'] == 800 + assert media_info['height'] == 600 + + # Verify file was saved + media_path = Path(app.config['DATA_PATH']) / 'media' / media_info['path'] + assert media_path.exists() + + # Verify it's actually a JPEG file + saved_img = Image.open(media_path) + assert saved_img.format == 'JPEG' + + class TestImageOptimization: """Test optimize_image function"""