2016-11-29 11:43:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2022-11-07 18:10:33 +00:00
|
|
|
from unittest import mock
|
2016-11-29 11:43:03 +00:00
|
|
|
import os
|
2019-12-06 02:54:11 +00:00
|
|
|
import six
|
2016-11-29 11:43:03 +00:00
|
|
|
|
2019-12-06 02:54:11 +00:00
|
|
|
from pungi.scripts.config_validate import cli_main
|
|
|
|
from tests import helpers
|
2016-11-29 11:43:03 +00:00
|
|
|
|
|
|
|
|
2019-12-06 02:54:11 +00:00
|
|
|
HERE = os.path.abspath(os.path.dirname(__file__))
|
2020-02-07 05:53:20 +00:00
|
|
|
DUMMY_CONFIG = os.path.join(HERE, "data/dummy-pungi.conf")
|
|
|
|
SCHEMA_OVERRIDE = os.path.join(HERE, "data/dummy-override.json")
|
2016-11-29 11:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigValidateScriptTest(helpers.PungiTestCase):
|
2020-02-07 05:53:20 +00:00
|
|
|
@mock.patch("sys.argv", new=["pungi-config-validate", DUMMY_CONFIG])
|
|
|
|
@mock.patch("sys.stderr", new_callable=six.StringIO)
|
|
|
|
@mock.patch("sys.stdout", new_callable=six.StringIO)
|
2019-12-06 02:54:11 +00:00
|
|
|
def test_validate_dummy_config(self, stdout, stderr):
|
|
|
|
cli_main()
|
2020-02-07 05:53:20 +00:00
|
|
|
self.assertEqual("", stdout.getvalue())
|
|
|
|
self.assertEqual("", stderr.getvalue())
|
|
|
|
|
|
|
|
@mock.patch(
|
|
|
|
"sys.argv",
|
|
|
|
new=[
|
|
|
|
"pungi-config-validate",
|
|
|
|
DUMMY_CONFIG,
|
|
|
|
"--schema-override",
|
|
|
|
SCHEMA_OVERRIDE,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@mock.patch("sys.stderr", new_callable=six.StringIO)
|
|
|
|
@mock.patch("sys.stdout", new_callable=six.StringIO)
|
|
|
|
@mock.patch("sys.exit")
|
2020-02-03 11:43:27 +00:00
|
|
|
def test_schema_override(self, exit, stdout, stderr):
|
|
|
|
cli_main()
|
2020-02-07 05:53:20 +00:00
|
|
|
self.assertTrue(
|
|
|
|
stdout.getvalue().startswith(
|
|
|
|
"Failed validation in pkgset_source: 'repos' is not one of"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual("", stderr.getvalue())
|
2020-02-03 11:43:27 +00:00
|
|
|
exit.assert_called_once_with(1)
|