[Merge] Merge with main server.

bzr revid: mdi@tinyerp.com-20121101042733-1h2mai7d33oz2re3
This commit is contained in:
Divyesh Makwana (Open ERP)
2012-11-01 09:57:33 +05:30
5 changed files with 69 additions and 9 deletions
+11
View File
@@ -104,3 +104,14 @@ TestCase subclasses
.. automodule:: openerp.tests.common
:members:
.. note::
The `setUp` and `tearDown` methods are not part of the tests. Uncaught
exceptions in those methods are errors, not test failures. In particular,
a failing `setUp` will not be followed by a `tearDown` causing any
allocated resource in the `setUp` to not be released by the `tearDown`.
In the :py:class:`openerp.tests.common.TransactionCase` and
:py:class:`openerp.tests.common.SingleTransactionCase`, this means the
test suite can hang because of unclosed cursors.
+2 -2
View File
@@ -9,7 +9,7 @@ See the :ref:`test-framework` section in the :ref:`features` list.
"""
from . import test_expression, test_html_sanitize, test_ir_sequence, test_orm,\
test_per_class_teardown, \
test_basecase, \
test_view_validation, test_uninstall, test_misc, test_db_cursor
fast_suite = [
@@ -21,7 +21,7 @@ checks = [
test_html_sanitize,
test_db_cursor,
test_orm,
test_per_class_teardown,
test_basecase,
test_view_validation,
test_misc,
]
+26 -3
View File
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
"""
The module :mod:`openerp.tests.common` provides a few helper and classes to write
The module :mod:`openerp.tests.common` provides a few helpers and classes to write
tests.
"""
import os
import threading
import time
import unittest2
@@ -44,10 +43,11 @@ def stop_openerp():
"""
openerp.service.stop_services()
class BaseCase(unittest2.TestCase):
"""
Subclass of TestCase for common OpenERP-specific code.
This class is abstract and expects self.cr and self.uid to be initialized by subclasses.
"""
@classmethod
@@ -58,6 +58,29 @@ class BaseCase(unittest2.TestCase):
def registry(self, model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
@classmethod
def ref(self, xid):
""" Returns database ID corresponding to a given identifier.
:param xid: fully-qualified record identifier, in the form ``module.identifier``
:raise: ValueError if not found
"""
assert "." in xid, "this method requires a fully qualified parameter, in the following form: 'module.identifier'"
module, xid = xid.split('.')
_, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xid)
return id
@classmethod
def browse_ref(self, xid):
""" Returns a browsable record for the given identifier.
:param xid: fully-qualified record identifier, in the form ``module.identifier``
:raise: ValueError if not found
"""
assert "." in xid, "this method requires a fully qualified parameter, in the following form: 'module.identifier'"
module, xid = xid.split('.')
return self.registry('ir.model.data').get_object(self.cr, self.uid, module, xid)
class TransactionCase(BaseCase):
"""
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import unittest2
import openerp
import common
class test_per_class_teardown(common.SingleTransactionCase):
class test_single_transaction_case(common.SingleTransactionCase):
"""
Check the whole-class transaction behavior of SingleTransactionCase.
"""
@@ -22,7 +21,30 @@ class test_per_class_teardown(common.SingleTransactionCase):
ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')])
self.assertEqual(1, len(ids), "Test partner not found.")
class test_per_method_teardown(common.TransactionCase):
def test_20a(self):
""" Create a partner with a XML ID """
cr, uid = self.cr, self.uid
res_partner = self.registry('res.partner')
ir_model_data = self.registry('ir.model.data')
pid, _ = res_partner.name_create(cr, uid, 'Mr Blue')
ir_model_data.create(cr, uid, {'name': 'test_partner_blue',
'module': 'base',
'model': 'res.partner',
'res_id': pid})
def test_20b(self):
""" Resolve xml id with ref() and browse_ref() """
cr, uid = self.cr, self.uid
res_partner = self.registry('res.partner')
xid = 'base.test_partner_blue'
p_ref = self.ref(xid)
self.assertTrue(p_ref, "ref() should resolve xid to database ID")
partner = res_partner.browse(cr, uid, p_ref)
p_browse_ref = self.browse_ref(xid)
self.assertEqual(partner, p_browse_ref, "browse_ref() should resolve xid to browse records")
class test_transaction_case(common.TransactionCase):
"""
Check the per-method transaction behavior of TransactionCase.
"""
+5 -1
View File
@@ -381,7 +381,11 @@ class YamlInterpreter(object):
return False
return val
view = view_info and etree.fromstring(view_info['arch'].encode('utf-8')) or False
if view_info:
arch = etree.fromstring(view_info['arch'].encode('utf-8'))
view = arch if len(arch) else False
else:
view = False
fields = fields or {}
if view is not False:
fg = view_info['fields']