1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
"""Tests for Hassio."""
from unittest.mock import patch
import aiohttp
import pytest
from pyhaversion import (
HaVersion,
HaVersionChannel,
HaVersionInputException,
HaVersionNotModifiedException,
HaVersionSource,
)
from tests.common import fixture
from .const import HEADERS, STABLE_VERSION
@pytest.mark.asyncio
async def test_stable_version(aresponses):
"""Test hassio stable."""
aresponses.add(
"version.home-assistant.io",
"/stable.json",
"get",
aresponses.Response(text=fixture("supervisor/default", False), status=200, headers=HEADERS),
)
async with aiohttp.ClientSession() as session:
haversion = HaVersion(session=session, source=HaVersionSource.SUPERVISOR)
await haversion.get_version()
assert haversion.version == STABLE_VERSION
@pytest.mark.asyncio
async def test_beta_version(HaVersion):
"""Test hassio beta."""
with patch(
"pyhaversion.supervisor.HaVersionSupervisor.fetch",
return_value=fixture("supervisor/default"),
):
async with aiohttp.ClientSession() as session:
haversion = HaVersion(
session=session,
source=HaVersionSource.SUPERVISOR,
channel=HaVersionChannel.BETA,
board="test",
image="test",
)
await haversion.get_version()
assert haversion.version == STABLE_VERSION
@pytest.mark.asyncio
async def test_input_exception(HaVersion):
"""Test input exception."""
with pytest.raises(HaVersionInputException):
HaVersion(source=HaVersionSource.SUPERVISOR)
@pytest.mark.asyncio
async def test_etag(aresponses):
"""Test hassio etag."""
aresponses.add(
"version.home-assistant.io",
"/stable.json",
"get",
aresponses.Response(
text=fixture("supervisor/default", False),
status=200,
headers={**HEADERS, "Etag": "test"},
),
)
aresponses.add(
"version.home-assistant.io",
"/stable.json",
"get",
aresponses.Response(status=304, headers=HEADERS),
)
async with aiohttp.ClientSession() as session:
haversion = HaVersion(session=session, source=HaVersionSource.SUPERVISOR)
await haversion.get_version(etag=haversion.etag)
assert haversion.version == STABLE_VERSION
with pytest.raises(HaVersionNotModifiedException):
await haversion.get_version(etag=haversion.etag)
|