From 3774ad65d714ec8693fa3cf8b915bbc8e4b07bf7 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 3 Dec 2010 15:20:35 +0100 Subject: [PATCH] [FIX] base,yaml: fixed !assert with "count" attribute in yaml tests + enabled more tests in base bzr revid: odo@openerp.com-20101203142035-3h1min1htys5lhop --- bin/addons/__init__.py | 3 +-- bin/addons/base/__openerp__.py | 2 +- bin/addons/base/test/base_test.yml | 11 ++++------- bin/tools/yaml_import.py | 12 ++++++++---- bin/tools/yaml_tag.py | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 814c701e51f..2413b21ce4e 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -649,8 +649,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, **kwargs): try: _load_data(cr, module_name, id_map, mode, 'test') except Exception, e: - logger.notifyChannel('ERROR', netsvc.LOG_TEST, e) - pass + logging.getLogger('test').exception('Tests failed to execute in %s module %s', module_name) finally: if tools.config.options['test_commit']: cr.commit() diff --git a/bin/addons/base/__openerp__.py b/bin/addons/base/__openerp__.py index ba07ead0fba..d57a8878199 100644 --- a/bin/addons/base/__openerp__.py +++ b/bin/addons/base/__openerp__.py @@ -85,7 +85,7 @@ ], 'test': [ 'test/base_test.xml', - #'test/base_test.yml' + 'test/base_test.yml', 'test/test_context.xml', 'test/bug_lp541545.xml', ], diff --git a/bin/addons/base/test/base_test.yml b/bin/addons/base/test/base_test.yml index 81a818f80c2..ab0de1c4e65 100644 --- a/bin/addons/base/test/base_test.yml +++ b/bin/addons/base/test/base_test.yml @@ -1,9 +1,6 @@ - | - Safe_Eval Scenario: - In order to check that common dangerous operations are - not allowed by the safe_eval mechanism, attempt to - evaluate some bad expressions, and verify that it triggers - an error. + To check that common dangerous operations are not allowed by the safe_eval mechanism, attempt to + evaluate unauthorized expressions, and verify that they trigger an error. - 1. Try a few common expressions to verify they work with safe_eval - @@ -47,11 +44,11 @@ from tools.safe_eval import safe_eval try: safe_eval('open("/etc/passwd","r")') - assert False, "safe_eval should not allow arbitrary expressions" + assert False, "safe_eval should not allow calling open() builtin" except NameError: pass except: # NameError should be raised because open() builtin is not found, # but other exceptions probably indicate that open() was executed! - assert False, "safe_eval should not allow arbitrary expressions" + assert False, "safe_eval should not allow calling open() builtin" diff --git a/bin/tools/yaml_import.py b/bin/tools/yaml_import.py index 0098e4e2117..6e5a581be73 100644 --- a/bin/tools/yaml_import.py +++ b/bin/tools/yaml_import.py @@ -34,7 +34,8 @@ def is_comment(node): return isinstance(node, types.StringTypes) def is_assert(node): - return _is_yaml_mapping(node, yaml_tag.Assert) + return isinstance(node, yaml_tag.Assert) \ + or _is_yaml_mapping(node, yaml_tag.Assert) def is_record(node): return _is_yaml_mapping(node, yaml_tag.Record) @@ -218,19 +219,22 @@ class YamlInterpreter(object): elif assertion.search: q = eval(assertion.search, self.eval_context) ids = self.pool.get(assertion.model).search(self.cr, self.uid, q, context=assertion.context) - if not ids: + else: raise YamlImportException('Nothing to assert: you must give either an id or a search criteria.') return ids def process_assert(self, node): - assertion, expressions = node.items()[0] + if isinstance(node, dict): + assertion, expressions = node.items()[0] + else: + assertion, expressions = node, [] if self.isnoupdate(assertion) and self.mode != 'init': self.logger.warn('This assertion was not evaluated ("%s").' % assertion.string) return model = self.get_model(assertion.model) ids = self._get_assertion_id(assertion) - if assertion.count and len(ids) != assertion.count: + if assertion.count is not None and len(ids) != assertion.count: msg = 'assertion "%s" failed!\n' \ ' Incorrect search count:\n' \ ' expected count: %d\n' \ diff --git a/bin/tools/yaml_tag.py b/bin/tools/yaml_tag.py index e12aecdcd96..20aabf1c54c 100644 --- a/bin/tools/yaml_tag.py +++ b/bin/tools/yaml_tag.py @@ -16,7 +16,7 @@ class YamlTag(object): return "<%s %s>" % (self.__class__.__name__, sorted(self.__dict__.items())) class Assert(YamlTag): - def __init__(self, model, id, severity=logging.WARNING, string="NONAME", **kwargs): + def __init__(self, model, id=None, severity=logging.WARNING, string="NONAME", **kwargs): self.model = model self.id = id self.severity = severity