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.
This commit is contained in:
Christian Kellner 2020-04-29 16:25:37 +02:00
parent 1fa3b88ab1
commit f3a4b2dfbf

View file

@ -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)