|
18 | 18 | from agentfield.media_providers import ( |
19 | 19 | FalProvider, |
20 | 20 | LiteLLMProvider, |
| 21 | + MiniMaxProvider, |
21 | 22 | OpenRouterProvider, |
22 | 23 | MediaProvider, |
23 | 24 | get_provider, |
@@ -179,6 +180,68 @@ def test_fal_provider_parse_image_size_dimensions(self, fal_provider): |
179 | 180 | result = fal_provider._parse_image_size("512x512") |
180 | 181 | assert result == {"width": 512, "height": 512} |
181 | 182 |
|
| 183 | + |
| 184 | +class _MiniMaxResponse: |
| 185 | + def __init__(self, payload): |
| 186 | + self.status = 200 |
| 187 | + self.payload = payload |
| 188 | + |
| 189 | + async def __aenter__(self): |
| 190 | + return self |
| 191 | + |
| 192 | + async def __aexit__(self, exc_type, exc, tb): |
| 193 | + return False |
| 194 | + |
| 195 | + async def json(self): |
| 196 | + return self.payload |
| 197 | + |
| 198 | + |
| 199 | +class _MiniMaxSession: |
| 200 | + def __init__(self, payload): |
| 201 | + self.payload = payload |
| 202 | + self.request = None |
| 203 | + |
| 204 | + async def __aenter__(self): |
| 205 | + return self |
| 206 | + |
| 207 | + async def __aexit__(self, exc_type, exc, tb): |
| 208 | + return False |
| 209 | + |
| 210 | + def post(self, endpoint, **kwargs): |
| 211 | + self.request = (endpoint, kwargs) |
| 212 | + return _MiniMaxResponse(self.payload) |
| 213 | + |
| 214 | + |
| 215 | +class TestMiniMaxProvider: |
| 216 | + @pytest.mark.asyncio |
| 217 | + async def test_generate_music_url_output(self): |
| 218 | + session = _MiniMaxSession( |
| 219 | + {"base_resp": {"status_code": 0}, "data": {"audio": "https://example.test/music.mp3"}} |
| 220 | + ) |
| 221 | + provider = MiniMaxProvider(api_key="test-key") |
| 222 | + |
| 223 | + with patch("aiohttp.ClientSession", return_value=session): |
| 224 | + result = await provider.generate_music("ambient piano", output_format="url") |
| 225 | + |
| 226 | + assert result.audio.url == "https://example.test/music.mp3" |
| 227 | + assert result.audio.data is None |
| 228 | + assert session.request[1]["json"]["output_format"] == "url" |
| 229 | + |
| 230 | + @pytest.mark.asyncio |
| 231 | + async def test_generate_music_hex_output_uses_audiooutput_base64_contract(self): |
| 232 | + audio_bytes = b"minimax-music" |
| 233 | + session = _MiniMaxSession( |
| 234 | + {"base_resp": {"status_code": 0}, "data": {"audio": audio_bytes.hex()}} |
| 235 | + ) |
| 236 | + provider = MiniMaxProvider(api_key="test-key") |
| 237 | + |
| 238 | + with patch("aiohttp.ClientSession", return_value=session): |
| 239 | + result = await provider.generate_music("ambient piano", output_format="hex") |
| 240 | + |
| 241 | + assert result.audio.url is None |
| 242 | + assert result.audio.get_bytes() == audio_bytes |
| 243 | + assert session.request[1]["json"]["output_format"] == "hex" |
| 244 | + |
182 | 245 | def test_fal_provider_parse_image_size_invalid_fallback(self, fal_provider): |
183 | 246 | """FalProvider should fallback to square_hd for invalid sizes.""" |
184 | 247 | assert fal_provider._parse_image_size("invalid") == "square_hd" |
|
0 commit comments