2021-02-04 08:59:41 +00:00
|
|
|
"""Tests for hassfest version."""
|
2024-03-08 18:16:38 +00:00
|
|
|
|
2024-08-28 14:38:12 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2021-02-04 08:59:41 +00:00
|
|
|
import pytest
|
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from script.hassfest.manifest import (
|
|
|
|
CUSTOM_INTEGRATION_MANIFEST_SCHEMA,
|
|
|
|
validate_version,
|
|
|
|
)
|
2024-08-28 14:38:12 +00:00
|
|
|
from script.hassfest.model import Config, Integration
|
2021-02-04 08:59:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def integration():
|
|
|
|
"""Fixture for hassfest integration model."""
|
2024-08-28 14:38:12 +00:00
|
|
|
integration = Integration(
|
|
|
|
"",
|
|
|
|
_config=Config(
|
|
|
|
root=Path(".").absolute(),
|
|
|
|
specific_integrations=None,
|
|
|
|
action="validate",
|
|
|
|
requirements=True,
|
|
|
|
core_integrations_path=Path("homeassistant/components"),
|
|
|
|
),
|
|
|
|
)
|
2022-11-17 08:10:37 +00:00
|
|
|
integration._manifest = {
|
2021-02-04 08:59:41 +00:00
|
|
|
"domain": "test",
|
|
|
|
"documentation": "https://example.com",
|
|
|
|
"name": "test",
|
|
|
|
"codeowners": ["@awesome"],
|
|
|
|
}
|
|
|
|
return integration
|
|
|
|
|
|
|
|
|
2023-02-20 10:42:56 +00:00
|
|
|
def test_validate_version_no_key(integration: Integration) -> None:
|
2021-02-04 08:59:41 +00:00
|
|
|
"""Test validate version with no key."""
|
|
|
|
validate_version(integration)
|
2021-05-17 13:48:41 +00:00
|
|
|
assert "No 'version' key in the manifest file." in [
|
|
|
|
x.error for x in integration.errors
|
|
|
|
]
|
2021-02-04 08:59:41 +00:00
|
|
|
|
|
|
|
|
2023-02-20 10:42:56 +00:00
|
|
|
def test_validate_custom_integration_manifest(integration: Integration) -> None:
|
2021-02-04 08:59:41 +00:00
|
|
|
"""Test validate custom integration manifest."""
|
|
|
|
|
2024-06-08 15:59:08 +00:00
|
|
|
integration.manifest["version"] = "lorem_ipsum"
|
2021-02-04 08:59:41 +00:00
|
|
|
with pytest.raises(vol.Invalid):
|
|
|
|
CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
|
|
|
|
|
2024-06-08 15:59:08 +00:00
|
|
|
integration.manifest["version"] = None
|
2021-02-04 08:59:41 +00:00
|
|
|
with pytest.raises(vol.Invalid):
|
|
|
|
CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
|
|
|
|
|
|
|
|
integration.manifest["version"] = "1"
|
|
|
|
schema = CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
|
|
|
|
assert schema["version"] == "1"
|