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
|
@ -0,0 +1 @@
|
|||
"""Hass.io Testframework."""
|
|
@ -0,0 +1 @@
|
|||
"""Add-ons tests."""
|
|
@ -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)
|
|
@ -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())
|
|
@ -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]
|
||||
envlist = lint
|
||||
envlist = lint, tests
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
flake8==3.6.0
|
||||
pylint==2.1.1
|
||||
pytest==4.0.0
|
||||
-r{toxinidir}/requirements.txt
|
||||
|
||||
[testenv:lint]
|
||||
|
@ -13,3 +14,8 @@ ignore_errors = True
|
|||
commands =
|
||||
flake8 hassio
|
||||
pylint --rcfile pylintrc hassio
|
||||
|
||||
[testenv:tests]
|
||||
basepython = python3
|
||||
commands =
|
||||
pytest --duration=10 tests
|
||||
|
|
Loading…
Reference in New Issue