def test_validate_raises_on_extra_field(config): config['driver']['extra'] = 'bar' with pytest.raises(marshmallow.ValidationError) as e: schema.validate(config) assert 'Unknown field' in str(e)
def test_validate_raises_on_invalid_field(config): config['driver']['name'] = int with pytest.raises(marshmallow.ValidationError) as e: schema.validate(config) assert 'Not a valid string.' in str(e)
def _combine(self): """ Perform a prioritized recursive merge of the `molecule_file` with defaults, interpolate the result with environment variables, and returns a new dict. :return: dict """ i = interpolation.Interpolator(interpolation.TemplateWithDefaults, os.environ) base = self._get_defaults() with util.open_file(self.molecule_file) as stream: try: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, util.safe_load(interpolated_config)) except interpolation.InvalidInterpolation as e: msg = ("parsing config file '{}'.\n\n" '{}\n{}'.format(self.molecule_file, e.place, e.string)) util.sysexit_with_message(msg) schema.validate(base) return base
def test_validate_raises_on_disallowed_field(config): disallowed_options = [ { 'defaults': { 'roles_path': '/path/to/roles' } }, { 'defaults': { 'library': '/path/to/library' } }, { 'defaults': { 'filter_plugins': '/path/to/filter_plugins' } }, { 'privilege_escalation': { 'foo': 'bar' } }, ] for options in disallowed_options: config['provisioner']['config_options'] = options with pytest.raises(marshmallow.ValidationError) as e: schema.validate(config) assert 'Disallowed user provided config option' in str(e)
def _convert(self): if self._v1.get('vagrant'): msg = 'Vagrant syle v1 config found' LOG.info(msg) self._set_vagrant_platforms() else: msg = 'Vagrant migrations only supported. Exiting.' util.sysexit_with_message(msg) self._set_provisioner() self._set_verifier() od = collections.OrderedDict( sorted(self._v2.items(), key=lambda t: t[0])) schema.validate(self._to_dict(od)) return od
def _combine(self): """ Perform a prioritized recursive merge of the `molecule_file` with defaults, interpolate the result with environment variables, and returns a new dict. :return: dict """ i = interpolation.Interpolator(interpolation.TemplateWithDefaults, os.environ) base = self._get_defaults() with util.open_file(self.molecule_file) as stream: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, util.safe_load(interpolated_config)) schema.validate(base) return base
def test_validate(config): data, errors = schema.validate(config) assert {} == errors
>>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/config.py ======= ======= try: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, >>>>>>> b1eb06d375fd544a849fcf5c39f51dc334b87338:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py >>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac util.safe_load(interpolated_config)) except interpolation.InvalidInterpolation as e: msg = ("parsing config file '{}'.\n\n" '{}\n{}'.format(self.molecule_file, e.place, e.string)) util.sysexit_with_message(msg) schema.validate(base) <<<<<<< HEAD <<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py return base ======= ======= <<<<<<< HEAD:molecule/config.py >>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac def _interpolate(self, stream, env, keep_string): env = self._set_env(env) i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env) try: return i.interpolate(stream, keep_string) except interpolation.InvalidInterpolation as e: msg = ("parsing config file '{}'.\n\n"