pungi/tests/test_config_validate_script.py
Haibo Lin 3eddcfccd8 Fix flake8 complaints - F401
F401 'dnf' imported but unused
F401 'imp' imported but unused
F401 'os' imported but unused
F401 'subprocess' imported but unused
F401 'sys' imported but unused
F401 'yum' imported but unused

JIRA: COMPOSE-4108
Signed-off-by: Haibo Lin <hlin@redhat.com>
2020-02-07 11:48:31 +08:00

39 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
import mock
import os
import six
from pungi.scripts.config_validate import cli_main
from tests import helpers
HERE = os.path.abspath(os.path.dirname(__file__))
DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
SCHEMA_OVERRIDE = os.path.join(HERE, 'data/dummy-override.json')
class ConfigValidateScriptTest(helpers.PungiTestCase):
@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)
def test_validate_dummy_config(self, stdout, stderr):
cli_main()
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')
def test_schema_override(self, exit, stdout, stderr):
cli_main()
self.assertTrue(stdout.getvalue().startswith(
"Failed validation in pkgset_source: 'repos' is not one of"))
self.assertEqual('', stderr.getvalue())
exit.assert_called_once_with(1)