[FIX] base,yaml: fixed !assert with "count" attribute in yaml tests + enabled more tests in base

bzr revid: odo@openerp.com-20101203142035-3h1min1htys5lhop
This commit is contained in:
Olivier Dony 2010-12-03 15:20:35 +01:00
parent 0e4023932b
commit 3774ad65d7
5 changed files with 15 additions and 15 deletions

View File

@ -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()

View File

@ -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',
],

View File

@ -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"

View File

@ -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' \

View File

@ -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