Ejemplo n.º 1
0
    def test_dict_dot_notation_access(self):
        data = {
            'a': 'foo',
            'b': {
                'c': 'bar',
                'd': {
                    'e': 123,
                    'f': False,
                    'g': {},
                    'h': None
                }
            },
            'x': {},
            'y': None
        }

        self.assertEqual('foo', utils.get_dict_value(data, 'a'))
        self.assertEqual('bar', utils.get_dict_value(data, 'b.c'))
        self.assertEqual(123, utils.get_dict_value(data, 'b.d.e'))
        self.assertFalse(utils.get_dict_value(data, 'b.d.f'))
        self.assertDictEqual({}, utils.get_dict_value(data, 'b.d.g'))
        self.assertIsNone(utils.get_dict_value(data, 'b.d.h'))
        self.assertDictEqual({}, utils.get_dict_value(data, 'x'))
        self.assertIsNone(utils.get_dict_value(data, 'x.x'))
        self.assertIsNone(utils.get_dict_value(data, 'y'))
        self.assertIsNone(utils.get_dict_value(data, 'z'))
Ejemplo n.º 2
0
    def _validate_expressions(cls, spec):
        result = []
        expr_schema_paths = cls.get_expr_schema_paths()

        for expr_path, schema_path in six.iteritems(expr_schema_paths):
            expr = utils.get_dict_value(spec, expr_path) or ''
            errors = expressions.validate(expr).get('errors', [])

            for error in errors:
                error['spec_path'] = expr_path
                error['schema_path'] = schema_path

            result += errors

        return result