Esempio n. 1
0
    def test_invalid_config(self):
        """Test an existing configuration file but invalid"""
        c = Config(base_dir + '/static/config_invalid.ini')
        self.assertFalse(c.read())
        self.assertGreater(len(c.errors), 0)
        self.assertTrue('project_name' in c.errors)
        self.assertEqual('Missing', c.errors['project_name'])
        self.assertTrue('php.version' in c.errors)
        self.assertEqual('the value "8.0" is unacceptable.',
                         c.errors['php.version'])

        # Don't go further with python < 3.5
        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            c.display_errors()
        res = f.getvalue()

        regex = re.compile('Failed validating .*config_invalid.ini',
                           re.MULTILINE)
        self.assertRegex(res, regex)

        regex = re.compile('the value ".*8.0.*" is unacceptable', re.MULTILINE)
        self.assertRegex(res, regex)
Esempio n. 2
0
    def test_invalid_config(self):
        """Test an existing configuration file but invalid"""

        c = Config(base_dir + '/static/config_invalid.yml')
        self.assertFalse(c.read())

        self.assertGreater(len(c.error), 0)
        self.assertRegex(c.error, '.*Additional properties are not allowed.*')

        # The rest doesn't work, for an unknown reason
        pytest.skip('Error trying to capture stderr')
        return

        # Don't go further with python < 3.5
        try:
            from contextlib import redirect_stderr
        except Exception:
            return

        f = io.StringIO()
        with redirect_stderr(f):
            c.display_errors()
        err = f.getvalue()

        regex = re.compile('.*config_invalid.yml.*', re.MULTILINE)
        self.assertRegex(err, regex)

        regex = re.compile('.*Failed validating main config or plugin configs.*', re.MULTILINE)
        self.assertRegex(err, regex)

        regex = re.compile('Additional properties are not allowed.*', re.MULTILINE)
        self.assertRegex(err, regex)
Esempio n. 3
0
    def _get_config(self):
        config = Config(self.config_file)
        main_config = config.read()
        if main_config is False:
            config.display_errors()
            sys.exit(1)

        return main_config
Esempio n. 4
0
    def test_default_config(self):
        """Test the default config (exit if it exists)"""
        if os.path.isfile(package_utils.get_venv_basedir() + '/conf/compose.ini'):
            return

        c = Config()
        with self.assertRaisesRegex(IOError, "Config file .*compose.ini does not exist"):
            c.read()
Esempio n. 5
0
    def test_valid_config_no_project(self):
        """Test an existing and valid configuration file"""
        c = Config(base_dir + '/static/config_valid_network.yml')
        config = c.read()
        self.assertIs(dict, type(config))
        self.assertTrue('services' in config)

        self.assertTrue('project_name' in config)
        self.assertEqual('testnet', config['project_name'])
Esempio n. 6
0
def get_config(config: str):
    """Read main compose.ini file."""
    config = Config(config).read()

    if config is False:
        config.display_errors()
        sys.exit(1)

    return config
Esempio n. 7
0
    def get_config(self):
        """Read and validate config from config file"""
        config = Config(self.context['CONFIG'])
        main_config = config.read()
        if main_config is False:
            config.display_errors()
            sys.exit(1)

        return main_config
Esempio n. 8
0
def _get_config(config_file: str):
    """Read main stakkr.yml file."""
    config_reader = Config(config_file)
    config = config_reader.read()

    if config is False:
        config.display_errors()
        sys.exit(1)

    return config, config_reader.config_file
Esempio n. 9
0
def get_main_config(config: str):
    """Read main compose.ini file"""

    config = Config(config)
    main_config = config.read()

    if main_config is False:
        config.display_errors()
        sys.exit(1)

    return main_config['main']
Esempio n. 10
0
    def test_valid_config(self):
        """Test an existing and valid configuration file"""
        c = Config(base_dir + '/static/stakkr.yml')
        config = c.read()
        self.assertIs(dict, type(config))
        self.assertTrue('services' in config)

        self.assertTrue('php' in config['services'])
        self.assertTrue('version' in config['services']['php'])
        self.assertTrue('enabled' in config['services']['php'])
        self.assertEqual(7.2, config['services']['php']['version'])
        self.assertTrue(config['services']['php']['enabled'])

        self.assertTrue('apache' not in config['services'])

        self.assertTrue('project_name' in config)
        self.assertEqual('static', config['project_name'])
Esempio n. 11
0
    def test_valid_config(self):
        """Test an existing and valid configuration file"""
        from configobj import ConfigObj

        c = Config(base_dir + '/static/config_valid.ini')
        config = c.read()
        self.assertIs(ConfigObj, type(config))
        self.assertTrue('main' in config)
        self.assertTrue('services' in config['main'])
        self.assertTrue('php' in config['main']['services'])
        self.assertFalse('apache' in config['main']['services'])

        self.assertTrue('project_name' in config['main'])
        self.assertEqual('test', config['main']['project_name'])

        self.assertTrue('php.version' in config['main'])
        self.assertEqual('7.2', config['main']['php.version'])
Esempio n. 12
0
 def test_bad_config(self):
     """Test a non existing configuration file"""
     c = Config('/does/not/exists.yml')
     with self.assertRaisesRegex(IOError, "No such file or directory: '/does/not/exists.yml'"):
         c.read()
Esempio n. 13
0
 def test_bad_config(self):
     """Test a non existing configuration file"""
     c = Config('/does/not/exists')
     with self.assertRaisesRegex(
             IOError, "Config file /does/not/exists does not exist"):
         c.read()