init home-assistant
This commit is contained in:
143
home-assistant/tests/components/azure_devops/__init__.py
Normal file
143
home-assistant/tests/components/azure_devops/__init__.py
Normal file
@@ -0,0 +1,143 @@
|
||||
"""Tests for the Azure DevOps integration."""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Final
|
||||
|
||||
from aioazuredevops.models.build import Build, BuildDefinition
|
||||
from aioazuredevops.models.core import Project
|
||||
from aioazuredevops.models.work_item import WorkItem, WorkItemFields
|
||||
from aioazuredevops.models.work_item_type import Category, Icon, State, WorkItemType
|
||||
|
||||
from homeassistant.components.azure_devops.const import CONF_ORG, CONF_PAT, CONF_PROJECT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
ORGANIZATION: Final[str] = "testorg"
|
||||
PROJECT: Final[str] = "testproject"
|
||||
PAT: Final[str] = "abc123"
|
||||
|
||||
UNIQUE_ID = f"{ORGANIZATION}_{PROJECT}"
|
||||
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
CONF_ORG: ORGANIZATION,
|
||||
CONF_PROJECT: PROJECT,
|
||||
CONF_PAT: PAT,
|
||||
}
|
||||
|
||||
FIXTURE_REAUTH_INPUT = {
|
||||
CONF_PAT: PAT,
|
||||
}
|
||||
|
||||
|
||||
DEVOPS_PROJECT = Project(
|
||||
id="1234",
|
||||
name=PROJECT,
|
||||
description="Test Description",
|
||||
url=f"https://dev.azure.com/{ORGANIZATION}/{PROJECT}",
|
||||
state="wellFormed",
|
||||
revision=1,
|
||||
visibility="private",
|
||||
default_team=None,
|
||||
links=None,
|
||||
)
|
||||
|
||||
DEVOPS_BUILD_DEFINITION = BuildDefinition(
|
||||
build_id=9876,
|
||||
name="CI",
|
||||
url=f"https://dev.azure.com/{ORGANIZATION}/{PROJECT}/_apis/build/definitions/1",
|
||||
path="",
|
||||
build_type="build",
|
||||
queue_status="enabled",
|
||||
revision=1,
|
||||
)
|
||||
|
||||
DEVOPS_BUILD = Build(
|
||||
build_id=5678,
|
||||
build_number="1",
|
||||
status="completed",
|
||||
result="succeeded",
|
||||
source_branch="main",
|
||||
source_version="123",
|
||||
priority="normal",
|
||||
reason="manual",
|
||||
queue_time="2021-01-01T00:00:00Z",
|
||||
start_time="2021-01-01T00:00:00Z",
|
||||
finish_time="2021-01-01T00:00:00Z",
|
||||
definition=DEVOPS_BUILD_DEFINITION,
|
||||
project=DEVOPS_PROJECT,
|
||||
links=None,
|
||||
)
|
||||
|
||||
DEVOPS_BUILD_MISSING_DATA = Build(
|
||||
build_id=6789,
|
||||
definition=DEVOPS_BUILD_DEFINITION,
|
||||
project=DEVOPS_PROJECT,
|
||||
)
|
||||
|
||||
DEVOPS_BUILD_MISSING_PROJECT_DEFINITION = Build(
|
||||
build_id=9876,
|
||||
)
|
||||
|
||||
DEVOPS_WORK_ITEM_TYPES = [
|
||||
WorkItemType(
|
||||
name="Bug",
|
||||
reference_name="System.Bug",
|
||||
description="Bug",
|
||||
color="ff0000",
|
||||
icon=Icon(id="1234", url="https://example.com/icon.png"),
|
||||
is_disabled=False,
|
||||
xml_form="",
|
||||
fields=[],
|
||||
field_instances=[],
|
||||
transitions={},
|
||||
states=[
|
||||
State(name="New", color="ff0000", category=Category.PROPOSED),
|
||||
State(name="Active", color="ff0000", category=Category.IN_PROGRESS),
|
||||
State(name="Resolved", color="ff0000", category=Category.RESOLVED),
|
||||
State(name="Closed", color="ff0000", category=Category.COMPLETED),
|
||||
],
|
||||
url="",
|
||||
)
|
||||
]
|
||||
|
||||
DEVOPS_WORK_ITEM_IDS = [1]
|
||||
|
||||
DEVOPS_WORK_ITEMS = [
|
||||
WorkItem(
|
||||
id=1,
|
||||
rev=1,
|
||||
fields=WorkItemFields(
|
||||
area_path="",
|
||||
team_project="",
|
||||
iteration_path="",
|
||||
work_item_type="Bug",
|
||||
state="New",
|
||||
reason="New",
|
||||
assigned_to=None,
|
||||
created_date=datetime(2021, 1, 1),
|
||||
created_by=None,
|
||||
changed_date=datetime(2021, 1, 1),
|
||||
changed_by=None,
|
||||
comment_count=0,
|
||||
title="Test",
|
||||
microsoft_vsts_common_state_change_date=datetime(2021, 1, 1),
|
||||
microsoft_vsts_common_priority=1,
|
||||
),
|
||||
url="https://example.com",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
async def setup_integration(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> bool:
|
||||
"""Fixture for setting up the component."""
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return result
|
||||
69
home-assistant/tests/components/azure_devops/conftest.py
Normal file
69
home-assistant/tests/components/azure_devops/conftest.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""Test fixtures for Azure DevOps."""
|
||||
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.azure_devops.const import DOMAIN
|
||||
|
||||
from . import (
|
||||
DEVOPS_BUILD,
|
||||
DEVOPS_PROJECT,
|
||||
DEVOPS_WORK_ITEM_IDS,
|
||||
DEVOPS_WORK_ITEM_TYPES,
|
||||
DEVOPS_WORK_ITEMS,
|
||||
FIXTURE_USER_INPUT,
|
||||
PAT,
|
||||
UNIQUE_ID,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_devops_client() -> AsyncGenerator[MagicMock]:
|
||||
"""Mock the Azure DevOps client."""
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.azure_devops.coordinator.DevOpsClient",
|
||||
autospec=True,
|
||||
) as mock_client,
|
||||
patch(
|
||||
"homeassistant.components.azure_devops.config_flow.DevOpsClient",
|
||||
new=mock_client,
|
||||
),
|
||||
):
|
||||
devops_client = mock_client.return_value
|
||||
devops_client.authorized = True
|
||||
devops_client.pat = PAT
|
||||
devops_client.authorize.return_value = True
|
||||
devops_client.get_project.return_value = DEVOPS_PROJECT
|
||||
devops_client.get_builds.return_value = [DEVOPS_BUILD]
|
||||
devops_client.get_build.return_value = DEVOPS_BUILD
|
||||
devops_client.get_work_item_types.return_value = DEVOPS_WORK_ITEM_TYPES
|
||||
devops_client.get_work_item_ids.return_value = DEVOPS_WORK_ITEM_IDS
|
||||
devops_client.get_work_items.return_value = DEVOPS_WORK_ITEMS
|
||||
|
||||
yield devops_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_config_entry() -> MockConfigEntry:
|
||||
"""Create a mock config entry."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=FIXTURE_USER_INPUT,
|
||||
unique_id=UNIQUE_ID,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.azure_devops.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_entry:
|
||||
yield mock_entry
|
||||
@@ -0,0 +1,621 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'latest_build',
|
||||
'unique_id': 'testorg_1234_9876_latest_build',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'definition_id': 9876,
|
||||
'definition_name': 'CI',
|
||||
'finish_time': '2021-01-01T00:00:00Z',
|
||||
'friendly_name': 'testproject CI latest build',
|
||||
'id': 5678,
|
||||
'queue_time': '2021-01-01T00:00:00Z',
|
||||
'reason': 'manual',
|
||||
'result': 'succeeded',
|
||||
'source_branch': 'main',
|
||||
'source_version': '123',
|
||||
'start_time': '2021-01-01T00:00:00Z',
|
||||
'status': 'completed',
|
||||
'url': None,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_finish_time-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_finish_time',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build finish time',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'finish_time',
|
||||
'unique_id': 'testorg_1234_9876_finish_time',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_finish_time-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build finish time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_finish_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_id-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_id',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build id',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'build_id',
|
||||
'unique_id': 'testorg_1234_9876_build_id',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_id-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build id',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_id',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '5678',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_queue_time-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_queue_time',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build queue time',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'queue_time',
|
||||
'unique_id': 'testorg_1234_9876_queue_time',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_queue_time-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build queue time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_queue_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_reason-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_reason',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build reason',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'reason',
|
||||
'unique_id': 'testorg_1234_9876_reason',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_reason-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build reason',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_reason',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'manual',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_result-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_result',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build result',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'result',
|
||||
'unique_id': 'testorg_1234_9876_result',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_result-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build result',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_result',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'succeeded',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_source_branch-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_branch',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build source branch',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'source_branch',
|
||||
'unique_id': 'testorg_1234_9876_source_branch',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_source_branch-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build source branch',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_branch',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'main',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_source_version-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_version',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build source version',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'source_version',
|
||||
'unique_id': 'testorg_1234_9876_source_version',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_source_version-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build source version',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_version',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '123',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_start_time-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_start_time',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': <RegistryEntryHider.INTEGRATION: 'integration'>,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build start time',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'start_time',
|
||||
'unique_id': 'testorg_1234_9876_start_time',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_start_time-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build start time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_start_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2021-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_url-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_url',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'CI latest build url',
|
||||
'platform': 'azure_devops',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'url',
|
||||
'unique_id': 'testorg_1234_9876_url',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.testproject_ci_latest_build_url-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build url',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_url',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'definition_id': 9876,
|
||||
'definition_name': 'CI',
|
||||
'finish_time': None,
|
||||
'friendly_name': 'testproject CI latest build',
|
||||
'id': 6789,
|
||||
'queue_time': None,
|
||||
'reason': None,
|
||||
'result': None,
|
||||
'source_branch': None,
|
||||
'source_version': None,
|
||||
'start_time': None,
|
||||
'status': None,
|
||||
'url': None,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_finish_time-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build finish time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_finish_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_id-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build id',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_id',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '6789',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_queue_time-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build queue time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_queue_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_reason-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build reason',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_reason',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_result-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build result',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_result',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_source_branch-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build source branch',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_branch',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_source_version-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build source version',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_source_version',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_start_time-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'timestamp',
|
||||
'friendly_name': 'testproject CI latest build start time',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_start_time',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors_missing_data[sensor.testproject_ci_latest_build_url-state-missing-data]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'testproject CI latest build url',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.testproject_ci_latest_build_url',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
244
home-assistant/tests/components/azure_devops/test_config_flow.py
Normal file
244
home-assistant/tests/components/azure_devops/test_config_flow.py
Normal file
@@ -0,0 +1,244 @@
|
||||
"""Test the Azure DevOps config flow."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.azure_devops.const import CONF_ORG, CONF_PROJECT, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import FIXTURE_REAUTH_INPUT, FIXTURE_USER_INPUT
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_show_user_form(hass: HomeAssistant) -> None:
|
||||
"""Test that the setup form is served."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
|
||||
async def test_authorization_error(
|
||||
hass: HomeAssistant,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps authorization error."""
|
||||
mock_devops_client.authorize.return_value = False
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "user"
|
||||
assert result2["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_reauth_authorization_error(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps authorization error."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
mock_devops_client.authorize.return_value = False
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_REAUTH_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_connection_error(
|
||||
hass: HomeAssistant,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps connection error."""
|
||||
mock_devops_client.authorize.side_effect = aiohttp.ClientError
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "user"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_reauth_connection_error(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps connection error."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
mock_devops_client.authorize.side_effect = aiohttp.ClientError
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_REAUTH_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_project_error(
|
||||
hass: HomeAssistant,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps connection error."""
|
||||
mock_devops_client.authorize.return_value = True
|
||||
mock_devops_client.authorized = True
|
||||
mock_devops_client.get_project.return_value = None
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "user"
|
||||
assert result2["errors"] == {"base": "project_error"}
|
||||
|
||||
|
||||
async def test_reauth_project_error(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test we show user form on Azure DevOps project error."""
|
||||
mock_devops_client.authorize.return_value = True
|
||||
mock_devops_client.authorized = True
|
||||
mock_devops_client.get_project.return_value = None
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_REAUTH_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["step_id"] == "reauth_confirm"
|
||||
assert result2["errors"] == {"base": "project_error"}
|
||||
|
||||
|
||||
async def test_reauth_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test reauth works."""
|
||||
mock_devops_client.authorize.return_value = False
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
mock_devops_client.authorize.return_value = True
|
||||
mock_devops_client.authorized = True
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_REAUTH_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result2["reason"] == "reauth_successful"
|
||||
|
||||
|
||||
async def test_full_flow_implementation(
|
||||
hass: HomeAssistant,
|
||||
mock_setup_entry: AsyncMock,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test registering an integration and finishing flow works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
FIXTURE_USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert (
|
||||
result2["title"]
|
||||
== f"{FIXTURE_USER_INPUT[CONF_ORG]}/{FIXTURE_USER_INPUT[CONF_PROJECT]}"
|
||||
)
|
||||
assert result2["data"][CONF_ORG] == FIXTURE_USER_INPUT[CONF_ORG]
|
||||
assert result2["data"][CONF_PROJECT] == FIXTURE_USER_INPUT[CONF_PROJECT]
|
||||
138
home-assistant/tests/components/azure_devops/test_init.py
Normal file
138
home-assistant/tests/components/azure_devops/test_init.py
Normal file
@@ -0,0 +1,138 @@
|
||||
"""Tests for init of Azure DevOps."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_load_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a successful setup entry."""
|
||||
assert await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.authorized
|
||||
assert mock_devops_client.authorize.call_count == 1
|
||||
assert mock_devops_client.get_builds.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_remove(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
async def test_auth_failed(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test a failed setup entry."""
|
||||
mock_devops_client.authorize.return_value = False
|
||||
mock_devops_client.authorized = False
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert not mock_devops_client.authorized
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_update_failed_project(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_project.side_effect = aiohttp.ClientError
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_project.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_update_failed_builds(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_builds.side_effect = aiohttp.ClientError
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_builds.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_no_builds(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_builds.return_value = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_builds.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_no_work_item_types(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_work_item_types.return_value = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_work_item_types.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_no_work_item_ids(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_work_item_ids.return_value = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_work_item_ids.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_no_work_items(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test a failed update entry."""
|
||||
mock_devops_client.get_work_items.return_value = None
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_devops_client.get_work_items.call_count == 1
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
91
home-assistant/tests/components/azure_devops/test_sensor.py
Normal file
91
home-assistant/tests/components/azure_devops/test_sensor.py
Normal file
@@ -0,0 +1,91 @@
|
||||
"""Tests for init of Azure DevOps."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import (
|
||||
DEVOPS_BUILD_MISSING_DATA,
|
||||
DEVOPS_BUILD_MISSING_PROJECT_DEFINITION,
|
||||
setup_integration,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
BASE_ENTITY_ID = "sensor.testproject_ci"
|
||||
SENSOR_KEYS = [
|
||||
"latest_build",
|
||||
"latest_build_id",
|
||||
"latest_build_reason",
|
||||
"latest_build_result",
|
||||
"latest_build_source_branch",
|
||||
"latest_build_source_version",
|
||||
"latest_build_queue_time",
|
||||
"latest_build_start_time",
|
||||
"latest_build_finish_time",
|
||||
"latest_build_url",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensors(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test sensor entities."""
|
||||
assert await setup_integration(hass, mock_config_entry)
|
||||
|
||||
for sensor_key in SENSOR_KEYS:
|
||||
assert (entry := entity_registry.async_get(f"{BASE_ENTITY_ID}_{sensor_key}"))
|
||||
|
||||
assert entry == snapshot(name=f"{entry.entity_id}-entry")
|
||||
|
||||
assert hass.states.get(entry.entity_id) == snapshot(
|
||||
name=f"{entry.entity_id}-state"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensors_missing_data(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test sensor entities with missing data."""
|
||||
mock_devops_client.get_builds.return_value = [DEVOPS_BUILD_MISSING_DATA]
|
||||
|
||||
assert await setup_integration(hass, mock_config_entry)
|
||||
|
||||
for sensor_key in SENSOR_KEYS:
|
||||
assert (entry := entity_registry.async_get(f"{BASE_ENTITY_ID}_{sensor_key}"))
|
||||
|
||||
assert hass.states.get(entry.entity_id) == snapshot(
|
||||
name=f"{entry.entity_id}-state-missing-data"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensors_missing_project_definition(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_devops_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test sensor entities with missing project and definition."""
|
||||
mock_devops_client.get_builds.return_value = [
|
||||
DEVOPS_BUILD_MISSING_PROJECT_DEFINITION
|
||||
]
|
||||
|
||||
assert await setup_integration(hass, mock_config_entry)
|
||||
|
||||
for sensor_key in SENSOR_KEYS:
|
||||
assert not entity_registry.async_get(f"{BASE_ENTITY_ID}_{sensor_key}")
|
||||
Reference in New Issue
Block a user