mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 02:56:31 +00:00
Add tests for hass.io (#817)
* Add tests for hass.io * Fix folder * Fix test command
This commit is contained in:
parent
644d13e3fa
commit
05b58d76b9
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Hass.io Testframework."""
|
1
tests/addons/__init__.py
Normal file
1
tests/addons/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Add-ons tests."""
|
41
tests/addons/test_config.py
Normal file
41
tests/addons/test_config.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""Validate Add-on configs."""
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from hassio.addons import validate as vd
|
||||||
|
|
||||||
|
from ..common import load_json_fixture
|
||||||
|
|
||||||
|
|
||||||
|
def test_basic_config():
|
||||||
|
"""Validate basic config and check the default values."""
|
||||||
|
config = load_json_fixture("basic-addon-config.json")
|
||||||
|
|
||||||
|
valid_config = vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
assert valid_config['name'] == "Test Add-on"
|
||||||
|
assert valid_config['image'] == "test/{arch}-my-custom-addon"
|
||||||
|
|
||||||
|
# Check defaults
|
||||||
|
assert not valid_config['host_network']
|
||||||
|
assert not valid_config['host_ipc']
|
||||||
|
assert not valid_config['host_dbus']
|
||||||
|
assert not valid_config['host_pid']
|
||||||
|
|
||||||
|
assert not valid_config['hassio_api']
|
||||||
|
assert not valid_config['homeassistant_api']
|
||||||
|
assert not valid_config['docker_api']
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_repository():
|
||||||
|
"""Validate basic config with invalid repository."""
|
||||||
|
config = load_json_fixture("basic-addon-config.json")
|
||||||
|
|
||||||
|
config['image'] = "home-assistant/no-valid-repo"
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
vd.SCHEMA_ADDON_CONFIG(config)
|
||||||
|
|
||||||
|
config['image'] = "homeassistant/no-valid-repo:no-tag-allow"
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
vd.SCHEMA_ADDON_CONFIG(config)
|
9
tests/common.py
Normal file
9
tests/common.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"""Common test functions."""
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def load_json_fixture(filename):
|
||||||
|
"""Load a fixture."""
|
||||||
|
path = Path(Path(__file__).parent.joinpath("fixtures"), filename)
|
||||||
|
return json.loads(path.read_text())
|
14
tests/fixtures/basic-addon-config.json
vendored
Normal file
14
tests/fixtures/basic-addon-config.json
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "Test Add-on",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"slug": "test_addon",
|
||||||
|
"description": "This is a basic Test Add-on",
|
||||||
|
"arch": ["amd64"],
|
||||||
|
"url": "https://www.home-assistant.io/",
|
||||||
|
"startup": "application",
|
||||||
|
"boot": "auto",
|
||||||
|
"map": ["config:rw", "ssl"],
|
||||||
|
"options": {},
|
||||||
|
"schema": {},
|
||||||
|
"image": "test/{arch}-my-custom-addon"
|
||||||
|
}
|
8
tox.ini
8
tox.ini
@ -1,10 +1,11 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = lint
|
envlist = lint, tests
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps =
|
||||||
flake8==3.6.0
|
flake8==3.6.0
|
||||||
pylint==2.1.1
|
pylint==2.1.1
|
||||||
|
pytest==4.0.0
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
@ -13,3 +14,8 @@ ignore_errors = True
|
|||||||
commands =
|
commands =
|
||||||
flake8 hassio
|
flake8 hassio
|
||||||
pylint --rcfile pylintrc hassio
|
pylint --rcfile pylintrc hassio
|
||||||
|
|
||||||
|
[testenv:tests]
|
||||||
|
basepython = python3
|
||||||
|
commands =
|
||||||
|
pytest --duration=10 tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user