molecule-hetznercloud/molecule_hetznercloud/test/unit/model/v2/test_platforms_section.py

83 lines
2.5 KiB
Python
Raw Normal View History

2019-10-23 11:04:57 +00:00
import pytest
2020-04-24 08:59:03 +00:00
from molecule.model import schema_v3
2019-10-23 11:04:57 +00:00
@pytest.fixture
def _model_platform_hetznercloud_section_data():
return {
"driver": {"name": "hetznercloud"},
"platforms": [
{
"name": "instance",
"server_type": "",
2021-01-06 14:21:42 +00:00
"volumes": [],
2019-10-23 11:04:57 +00:00
"image": "",
"location": "",
"datacenter": "",
"user_data": "",
}
],
}
@pytest.mark.parametrize(
"_config", ["_model_platform_hetznercloud_section_data"], indirect=True
)
def test_platforms_hetznercloud(_config):
2020-04-24 08:59:03 +00:00
assert {} == schema_v3.validate(_config)
2019-10-23 11:04:57 +00:00
@pytest.fixture
def _model_platforms_hetznercloud_errors_section_data():
return {
"driver": {"name": "hetznercloud"},
"platforms": [
{
"name": 0,
"server_type": 0,
2021-01-06 10:18:53 +00:00
"volumes": [],
2019-10-23 11:04:57 +00:00
"image": 0,
"location": 0,
"datacenter": 0,
"user_data": 0,
}
],
}
2019-11-16 01:25:08 +00:00
@pytest.mark.skip(reason="https://github.com/ansible/molecule/issues/2442")
2019-10-23 11:04:57 +00:00
@pytest.mark.parametrize(
"_config", ["_model_platforms_hetznercloud_errors_section_data"], indirect=True
)
def test_platforms_hetznercloud_has_errors(_config):
expected_config = {
"platforms": [
{
0: [
{
"name": ["must be of string type"],
"server_type": ["must be of string type"],
2021-01-06 14:21:42 +00:00
"volumes": ["must be of list type"],
2019-10-23 11:04:57 +00:00
"image": ["must be of string type"],
"location": ["must be of string type"],
"datacenter": ["must be of string type"],
"user_data": ["must be of string type"],
}
]
}
]
}
2020-04-24 08:59:03 +00:00
assert expected_config == schema_v3.validate(_config)
2019-10-23 11:04:57 +00:00
2019-11-16 01:25:08 +00:00
@pytest.mark.skip(reason="https://github.com/ansible/molecule/issues/2442")
2019-10-23 11:04:57 +00:00
@pytest.mark.parametrize(
"_config", ["_model_platform_hetznercloud_section_data"], indirect=True
)
@pytest.mark.parametrize("_required_field", ("server_type", "image"))
def test_platforms_hetznercloud_fields_required(_config, _required_field):
del _config["platforms"][0][_required_field]
expected_config = {"platforms": [{0: [{_required_field: ["required field"]}]}]}
2020-04-24 08:59:03 +00:00
assert expected_config == schema_v3.validate(_config)