Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
import pytest
from unittest.mock import AsyncMock
from routes.generate_code import ModelSelectionStage
from llm import Llm
class TestModelSelectionAllKeys:
"""Test model selection when Gemini, Anthropic, and OpenAI API keys are present."""
def setup_method(self):
"""Set up test fixtures."""
mock_throw_error = AsyncMock()
self.model_selector = ModelSelectionStage(mock_throw_error)
@pytest.mark.asyncio
async def test_gemini_anthropic_create(self):
"""All keys text create: fixed order for four variants."""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="text",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
Llm.GPT_5_6_SOL_HIGH,
Llm.CLAUDE_OPUS_5_HIGH,
Llm.GEMINI_3_1_PRO_PREVIEW_LOW,
]
assert models == expected
@pytest.mark.asyncio
async def test_gemini_anthropic_create_image(self):
"""All keys image create: fixed order for four variants."""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="image",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.CLAUDE_OPUS_5_5_MEDIUM,
Llm.GEMINI_3_FLASH_PREVIEW_HIGH,
Llm.CLAUDE_OPUS_5_5_XHIGH,
Llm.GPT_6_1_SOL_HIGH,
]
assert models == expected
@pytest.mark.asyncio
async def test_gemini_anthropic_update_text(self):
"""All keys text update: uses two fast edit variants."""
models = await self.model_selector.select_models(
generation_type="update",
input_mode="text",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
Llm.GPT_6_1_SOL_LOW,
]
assert models == expected
@pytest.mark.asyncio
async def test_gemini_anthropic_update(self):
"""All keys image update: uses two fast edit variants."""
models = await self.model_selector.select_models(
generation_type="update",
input_mode="image",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
Llm.GPT_6_1_SOL_LOW,
]
assert models == expected
@pytest.mark.asyncio
async def test_video_create_prefers_gemini_minimal_then_3_1_high(self):
"""Video create always uses two Gemini variants in fixed order."""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="video",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
Llm.GEMINI_3_1_PRO_PREVIEW_HIGH,
]
assert models == expected
@pytest.mark.asyncio
async def test_video_update_prefers_gemini_minimal_then_3_1_high(self):
"""Video update always uses the same two Gemini variants as video create."""
models = await self.model_selector.select_models(
generation_type="update",
input_mode="video",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key="key",
)
expected = [
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
Llm.GEMINI_3_1_PRO_PREVIEW_HIGH,
]
assert models == expected
class TestModelSelectionOpenAIAnthropic:
"""Test model selection when only OpenAI and Anthropic keys are present."""
def setup_method(self):
"""Set up test fixtures."""
mock_throw_error = AsyncMock()
self.model_selector = ModelSelectionStage(mock_throw_error)
@pytest.mark.asyncio
async def test_openai_anthropic(self):
"""OpenAI + Anthropic: Claude Opus 4.8 medium, GPT 5.5 high, GPT 5.5 low, cycling"""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="text",
openai_api_key="key",
anthropic_api_key="key",
gemini_api_key=None,
)
expected = [
Llm.CLAUDE_OPUS_4_8_MEDIUM,
Llm.GPT_5_5_HIGH,
Llm.GPT_5_5_LOW,
Llm.CLAUDE_OPUS_4_8_MEDIUM,
]
assert models == expected
class TestModelSelectionAnthropicOnly:
"""Test model selection when only Anthropic key is present."""
def setup_method(self):
"""Set up test fixtures."""
mock_throw_error = AsyncMock()
self.model_selector = ModelSelectionStage(mock_throw_error)
@pytest.mark.asyncio
async def test_anthropic_only(self):
"""Anthropic only: Claude Opus 4.8 medium and Claude Sonnet 4.6 cycling"""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="text",
openai_api_key=None,
anthropic_api_key="key",
gemini_api_key=None,
)
expected = [
Llm.CLAUDE_OPUS_4_8_MEDIUM,
Llm.CLAUDE_SONNET_4_6,
Llm.CLAUDE_OPUS_4_8_MEDIUM,
Llm.CLAUDE_SONNET_4_6,
]
assert models == expected
class TestModelSelectionOpenAIOnly:
"""Test model selection when only OpenAI key is present."""
def setup_method(self):
"""Set up test fixtures."""
mock_throw_error = AsyncMock()
self.model_selector = ModelSelectionStage(mock_throw_error)
@pytest.mark.asyncio
async def test_openai_only(self):
"""OpenAI only: GPT 5.5 high and low, cycling"""
models = await self.model_selector.select_models(
generation_type="create",
input_mode="text",
openai_api_key="key",
anthropic_api_key=None,
gemini_api_key=None,
)
expected = [
Llm.GPT_5_5_HIGH,
Llm.GPT_5_5_LOW,
Llm.GPT_5_5_HIGH,
Llm.GPT_5_5_LOW,
]
assert models == expected
class TestModelSelectionNoKeys:
"""Test model selection when no API keys are present."""
def setup_method(self):
"""Set up test fixtures."""
mock_throw_error = AsyncMock()
self.model_selector = ModelSelectionStage(mock_throw_error)
@pytest.mark.asyncio
async def test_no_keys_raises_error(self):
"""No keys: Should raise an exception"""
with pytest.raises(Exception, match="No API key"):
await self.model_selector.select_models(
generation_type="create",
input_mode="text",
openai_api_key=None,
anthropic_api_key=None,
gemini_api_key=None,
)