Files
invoke-ai--invokeai/tests/backend/model_manager/test_external_api_config.py
T
wehub-resource-sync cddb07a176
build container image / cpu (push) Waiting to run
build container image / cuda (push) Waiting to run
build container image / rocm (push) Waiting to run
frontend tests / frontend-tests (push) Waiting to run
openapi checks / openapi-checks (push) Waiting to run
python tests / py3.12: macos-default (push) Waiting to run
python tests / py3.11: windows-cpu (push) Waiting to run
python tests / py3.12: windows-cpu (push) Waiting to run
python tests / py3.11: linux-cpu (push) Waiting to run
python tests / py3.12: linux-cpu (push) Waiting to run
typegen checks / typegen-checks (push) Waiting to run
uv lock checks / uv-lock-checks (push) Waiting to run
frontend checks / frontend-checks (push) Waiting to run
lfs checks / lfs-check (push) Waiting to run
python checks / python-checks (push) Waiting to run
python tests / py3.11: macos-default (push) Waiting to run
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:06 +08:00

55 lines
1.8 KiB
Python

import pytest
from pydantic import ValidationError
from invokeai.backend.model_manager.configs.external_api import (
ExternalApiModelConfig,
ExternalApiModelDefaultSettings,
ExternalImageSize,
ExternalModelCapabilities,
)
def test_external_api_model_config_defaults() -> None:
capabilities = ExternalModelCapabilities(modes=["txt2img"], supports_seed=True)
config = ExternalApiModelConfig(
name="Test External",
provider_id="openai",
provider_model_id="gpt-image-1",
capabilities=capabilities,
)
assert config.path == "external://openai/gpt-image-1"
assert config.source == "external://openai/gpt-image-1"
assert config.hash == "external:openai:gpt-image-1"
assert config.file_size == 0
assert config.default_settings is None
assert config.capabilities.supports_seed is True
def test_external_api_model_capabilities_allows_aspect_ratio_sizes() -> None:
capabilities = ExternalModelCapabilities(
modes=["txt2img"],
allowed_aspect_ratios=["1:1"],
aspect_ratio_sizes={"1:1": ExternalImageSize(width=1024, height=1024)},
)
assert capabilities.aspect_ratio_sizes is not None
assert capabilities.aspect_ratio_sizes["1:1"].width == 1024
def test_external_api_model_config_rejects_extra_fields() -> None:
with pytest.raises(ValidationError):
ExternalModelCapabilities(modes=["txt2img"], supports_seed=True, extra_field=True) # type: ignore
with pytest.raises(ValidationError):
ExternalApiModelDefaultSettings(width=512, extra_field=True) # type: ignore
def test_external_api_model_config_validates_limits() -> None:
with pytest.raises(ValidationError):
ExternalModelCapabilities(modes=["txt2img"], max_images_per_request=0)
with pytest.raises(ValidationError):
ExternalApiModelDefaultSettings(width=0)