Azure DevOps integration tests (#114577)
* Add tests to azure devops * Remove Azure DevOps files from coverage * Add assertion for entity registration in test_sensors() * Remove unnecessary code in test_sensor.py * Refactor test_sensors function * Fix * Test unique id * Refactor * Refactor reauth_flow test in azure_devops module * Suggested changes, batched Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Changes * Use snapshot * Remove redundant entry fetch --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
7cb01f75ae
commit
17f0002549
7 changed files with 501 additions and 223 deletions
78
tests/components/azure_devops/test_init.py
Normal file
78
tests/components/azure_devops/test_init.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
"""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 == 2
|
||||
|
||||
assert mock_config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_remove(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state == 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 == ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_update_failed(
|
||||
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 == 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 == ConfigEntryState.SETUP_RETRY
|
Loading…
Add table
Add a link
Reference in a new issue