def test_property_access(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertEqual(123, self.eval('$.attr', obj)) self.assertEqual(123, self.eval('$.prop', obj)) self.assertEqual(123, self.eval('$?.prop', obj)) self.assertIsNone(self.eval('$?.prop', None)) self.assertRaises(AttributeError, self.eval, '$.invalid', obj)
def test_auto_yaqlization(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertRaises(exceptions.NoFunctionRegisteredException, self.eval, '$.get_d().d_attr', obj) obj = self._get_sample_class()() yaqlization.yaqlize(obj, auto_yaqlize_result=True) self.assertEqual(777, self.eval('$.get_d().d_attr', obj))
def test_auto_yaqlization(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertRaises( exceptions.NoFunctionRegisteredException, self.eval, '$.get_d().d_attr', obj) obj = self._get_sample_class()() yaqlization.yaqlize(obj, auto_yaqlize_result=True) self.assertEqual(777, self.eval('$.get_d().d_attr', obj))
def _auto_yaqlize(value, settings): if not settings['autoYaqlizeResult']: return if isinstance(value, type): cls = value else: cls = type(value) if cls.__module__ == int.__module__: return try: yaqlization.yaqlize(value, auto_yaqlize_result=True) except Exception: pass
def test_method_call_yaqlized_object(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertEqual(3, self.eval('$.m_foo(5, 2)', obj)) self.assertEqual(3, self.eval('$.m_foo(5, arg2 => 2)', obj)) self.assertEqual(3, self.eval('$.m_foo(arg2 => 2, arg1 => 6-1)', obj)) self.assertEqual('A', self.eval('$.bar(a)', obj)) self.assertEqual('B', self.eval('$.static(b)', obj)) self.assertEqual('C', self.eval('$.clsmethod(c)', obj)) self.assertRaises(exceptions.NoFunctionRegisteredException, self.eval, 'm_foo($, 5, 2)', obj) self.assertEqual(3, self.eval('$?.m_foo(5, 2)', obj)) self.assertIsNone(self.eval('$?.m_foo(5, 2)', None))
def test_method_call_yaqlized_object(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertEqual(3, self.eval('$.m_foo(5, 2)', obj)) self.assertEqual(3, self.eval('$.m_foo(5, arg2 => 2)', obj)) self.assertEqual(3, self.eval('$.m_foo(arg2 => 2, arg1 => 6-1)', obj)) self.assertEqual('A', self.eval('$.bar(a)', obj)) self.assertEqual('B', self.eval('$.static(b)', obj)) self.assertEqual('C', self.eval('$.clsmethod(c)', obj)) self.assertRaises( exceptions.NoFunctionRegisteredException, self.eval, 'm_foo($, 5, 2)', obj) self.assertEqual(3, self.eval('$?.m_foo(5, 2)', obj)) self.assertIsNone(self.eval('$?.m_foo(5, 2)', None))
def gen_rule_data(self): """ Generates the root data object for the YAQL evaluation. :return: """ self.root = collections.OrderedDict() # Config & versions, abbrevs self.root['config'] = self.config self.root['ebstall_version'] = versions.Version(self.ebstall_version) self.root['ebstall_version_initial'] = versions.Version(self.config.ebstall_version_initial) \ if self.config is not None else versions.Version('0') self.root['ebstall_cfg_version'] = versions.Version(self.config.ebstall_version) \ if self.config is not None else versions.Version('0') self.root['install_version'] = versions.Version(self.config.install_version) \ if self.config is not None else versions.Version('0') self.root['jboss_version'] = versions.Version(self.config.jboss_version) \ if self.config is not None else versions.Version('0') self.root['ejbca_version'] = versions.Version(self.config.ejbca_version) \ if self.config is not None else versions.Version('0') self.root['source_image_code'] = self.config.source_image_code \ if self.config is not None else None # Current OS info self.root['os'] = self.syscfg.get_os() # Installed packages packages = self.syscfg.get_installed_packages() self.root['pkgs'] = {x.name: x for x in packages} self.root['pkgs_lst'] = packages self.root['pkgs_map'] = {str(x): x for x in packages} # Allowing access to methods & attributes yaqlization.yaqlize(Config, blacklist=['set_config']) yaqlization.yaqlize(OSInfo) yaqlization.yaqlize(PackageInfo) return self.root
def test_method_call_yaqlized_class(self): cls = self._get_sample_class() yaqlization.yaqlize(cls) obj = cls() self.assertEqual(3, self.eval('$.m_foo(5, 2)', obj))
def test_method_call_blacklist_callable(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, blacklist=[lambda t: t.startswith('m_')]) self.assertRaises(AttributeError, self.eval, '$.m_foo(5, 2)', obj) self.assertEqual('A', self.eval('$.bar(a)', obj))
def test_indexation_blacklist(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, blacklist=[lambda t: t.startswith('_')]) self.assertEqual('key', self.eval('$[key]', obj)) self.assertRaises(KeyError, self.eval, '$[_key]', obj)
def test_property_access_blacklist(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, blacklist=['prop']) self.assertEqual(123, self.eval('$.attr', obj)) self.assertRaises(AttributeError, self.eval, '$.prop', obj)
def test_method_call_blacklist_regexp(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, blacklist=[re.compile('^m_*')]) self.assertRaises(AttributeError, self.eval, '$.m_foo(5, 2)', obj) self.assertEqual('A', self.eval('$.bar(a)', obj))
@specs.yaql_property(dsl_types.MuranoMetaClass) def targets(murano_meta_class): return murano_meta_class.targets @specs.yaql_property(dsl_types.MuranoMetaClass) def inherited(murano_meta_class): return murano_meta_class.inherited def register(context): funcs = ( type_name, type_usage, type_version, type_to_type_ref, methods, properties, ancestors, package, property_name, property_has_default, property_owner, property_usage, property_get_value, property_set_value, method_name, arguments, method_owner, method_invoke, types, package_name, package_version, argument_name, argument_has_default, argument_owner, cardinality, targets, inherited, get_meta ) for f in funcs: context.register_function(f) yaqlization.yaqlize(semantic_version.Version, whitelist=[ 'major', 'minor', 'patch', 'prerelease', 'build' ])
def test_indexation(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj) self.assertEqual('key', self.eval('$[key]', obj))
def test_method_call_forbidden(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, yaqlize_methods=False) self.assertRaises(exceptions.NoMethodRegisteredException, self.eval, '$.m_foo(5, 2)', obj)
def test_method_call_forbidden(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, yaqlize_methods=False) self.assertRaises( exceptions.NoMethodRegisteredException, self.eval, '$.m_foo(5, 2)', obj)
@specs.yaql_property(dsl_types.MuranoMetaClass) def cardinality(murano_meta_class): return murano_meta_class.cardinality @specs.yaql_property(dsl_types.MuranoMetaClass) def targets(murano_meta_class): return murano_meta_class.targets @specs.yaql_property(dsl_types.MuranoMetaClass) def inherited(murano_meta_class): return murano_meta_class.inherited def register(context): funcs = (type_name, type_usage, type_version, type_to_type_ref, methods, properties, ancestors, package, property_name, property_has_default, property_owner, property_usage, property_get_value, property_set_value, method_name, arguments, method_owner, method_invoke, types, package_name, package_version, argument_name, argument_has_default, argument_owner, argument_usage, cardinality, targets, inherited, get_meta) for f in funcs: context.register_function(f) yaqlization.yaqlize( semantic_version.Version, whitelist=['major', 'minor', 'patch', 'prerelease', 'build'])
def test_method_call_blacklist_string(self): obj = self._get_sample_class()() yaqlization.yaqlize(obj, blacklist=['m_foo']) self.assertRaises(AttributeError, self.eval, '$.m_foo(5, 2)', obj) self.assertEqual('A', self.eval('$.bar(a)', obj))