From 4e59c7595ed1de539b00148ba13fcc094e723d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 25 Jun 2019 12:50:07 +0200 Subject: [PATCH] config: Improve config validation for anyOf and oneOf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of just saying that there is a problem, give all possible reasons. JIRA: COMPOSE-3636 Signed-off-by: Lubomír Sedlář --- pungi/checks.py | 3 +++ tests/test_osbs_phase.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pungi/checks.py b/pungi/checks.py index ff38c6a3..e4d8dad1 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -200,6 +200,9 @@ def validate(config, offline=False): else: errors.append('Failed validation in %s: %s' % ( '.'.join([str(x) for x in error.path]), error.message)) + if error.validator in ("anyOf", "oneOf"): + for suberror in error.context: + errors.append(" Possible reason: %s" % suberror.message) return (errors + _validate_requires(schema, config, CONFIG_DEPS), warnings) diff --git a/tests/test_osbs_phase.py b/tests/test_osbs_phase.py index dd40ddaa..871e92d2 100644 --- a/tests/test_osbs_phase.py +++ b/tests/test_osbs_phase.py @@ -270,9 +270,13 @@ class OSBSThreadTest(helpers.PungiTestCase): config['osbs'] = { '^Server$': cfg } - self.assertEqual( - (['Failed validation in osbs.^Server$: %r is not valid under any of the given schemas' % cfg], []), - checks.validate(config, offline=True)) + errors, warnings = checks.validate(config, offline=True) + self.assertIn( + "Failed validation in osbs.^Server$: %r is not valid under any of the given schemas" % cfg, + errors, + ) + self.assertIn(" Possible reason: %r is a required property" % key, errors) + self.assertEqual([], warnings) @mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper') def test_minimal_run(self, KojiWrapper):