summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJames Falcon <james.falcon@canonical.com>2021-12-13 18:14:50 -0600
committerGitHub <noreply@github.com>2021-12-13 17:14:50 -0700
commit9a6e65a2a575055aadc1802004dbe3f343a54b89 (patch)
tree947352deb327475d9cb6af4951884c5e4c09eeae /tests
parent35711700e10c47dcfa16238ba0bd395813e5a511 (diff)
downloadvyos-cloud-init-9a6e65a2a575055aadc1802004dbe3f343a54b89.tar.gz
vyos-cloud-init-9a6e65a2a575055aadc1802004dbe3f343a54b89.zip
Schema processing changes (SC-676) (#1144)
* Use proper logging * Add parsing for patternProperties * Add label to annotate patternProperties * Log warning if schema parsing fails during metaschema processing * Some schema test fixes
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/config/test_schema.py55
1 files changed, 48 insertions, 7 deletions
diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py
index ed7ab527..40803cae 100644
--- a/tests/unittests/config/test_schema.py
+++ b/tests/unittests/config/test_schema.py
@@ -55,7 +55,7 @@ def get_module_variable(var_name) -> dict:
schemas = {}
files = list(
- Path(cloud_init_project_dir("../../cloudinit/config/")).glob("cc_*.py")
+ Path(cloud_init_project_dir("cloudinit/config/")).glob("cc_*.py")
)
modules = [mod.stem for mod in files]
@@ -215,12 +215,13 @@ class TestCloudConfigExamples:
@pytest.mark.parametrize("schema_id, example", params)
@skipUnlessJsonSchema()
def test_validateconfig_schema_of_example(self, schema_id, example):
- """ For a given example in a config module we test if it is valid
+ """For a given example in a config module we test if it is valid
according to the unified schema of all config modules
"""
config_load = safe_load(example)
validate_cloudconfig_schema(
- config_load, self.schema, strict=True)
+ config_load, self.schema[schema_id], strict=True
+ )
class ValidateCloudConfigFileTest(CiTestCase):
@@ -462,6 +463,44 @@ class GetSchemaDocTest(CiTestCase):
get_meta_doc(invalid_meta, schema)
self.assertIn(key, str(context_mgr.exception))
+ def test_label_overrides_property_name(self):
+ """get_meta_doc overrides property name with label."""
+ schema = {
+ "properties": {
+ "prop1": {
+ "type": "string",
+ "label": "label1",
+ },
+ "prop_no_label": {
+ "type": "string",
+ },
+ "prop_array": {
+ "label": 'array_label',
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "some_prop": {"type": "number"},
+ },
+ },
+ },
+ },
+ "patternProperties": {
+ "^.*$": {
+ "type": "string",
+ "label": "label2",
+ }
+ }
+ }
+ meta_doc = get_meta_doc(self.meta, schema)
+ assert "**label1:** (string)" in meta_doc
+ assert "**label2:** (string" in meta_doc
+ assert "**prop_no_label:** (string)" in meta_doc
+ assert "Each item in **array_label** list" in meta_doc
+
+ assert "prop1" not in meta_doc
+ assert ".*" not in meta_doc
+
class AnnotatedCloudconfigFileTest(CiTestCase):
maxDiff = None
@@ -626,9 +665,11 @@ def _get_meta_doc_examples():
examples_dir = Path(cloud_init_project_dir('doc/examples'))
assert examples_dir.is_dir()
- all_text_files = (f for f in examples_dir.glob('cloud-config*.txt')
- if not f.name.startswith('cloud-config-archive'))
- return all_text_files
+ return (
+ str(f)
+ for f in examples_dir.glob("cloud-config*.txt")
+ if not f.name.startswith("cloud-config-archive")
+ )
class TestSchemaDocExamples:
@@ -637,7 +678,7 @@ class TestSchemaDocExamples:
@pytest.mark.parametrize("example_path", _get_meta_doc_examples())
@skipUnlessJsonSchema()
def test_schema_doc_examples(self, example_path):
- validate_cloudconfig_file(str(example_path), self.schema)
+ validate_cloudconfig_file(example_path, self.schema)
class TestStrictMetaschema: