From f3a4b2dfbf717e3a579d41df7d2666cba0dd4bf6 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 29 Apr 2020 16:25:37 +0200 Subject: [PATCH] test/osbuild: add checks for Schema class Basic checks that `Schema`, initialization with no, an invalid and a valid schema. Check the latter can be used to do validation. --- test/test_osbuild.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_osbuild.py b/test/test_osbuild.py index b6c69283..f811826e 100644 --- a/test/test_osbuild.py +++ b/test/test_osbuild.py @@ -97,6 +97,23 @@ class TestDescriptions(unittest.TestCase): msg = f"{klass} '{name}' has invalid STAGE_OPTS\n\t" + str(e) self.fail(msg) + def test_schema(self): + schema = osbuild.meta.Schema(None) + self.assertFalse(schema) + + schema = osbuild.meta.Schema({"type": "bool"}) # should be 'boolean' + self.assertFalse(schema.check().valid) + self.assertFalse(schema) + + schema = osbuild.meta.Schema({"type": "array", "minItems": 3}) + self.assertTrue(schema.check().valid) + self.assertTrue(schema) + + res = schema.validate([1, 2]) + self.assertFalse(res) + res = schema.validate([1, 2, 3]) + self.assertTrue(res) + def test_validation(self): index = osbuild.meta.Index(os.curdir)